Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

derive Clone for Client #133

Open
databasedav opened this issue May 17, 2023 · 2 comments
Open

derive Clone for Client #133

databasedav opened this issue May 17, 2023 · 2 comments

Comments

@databasedav
Copy link

any reason we wouldn't want to do this? the internal Cluster is already wrapped in an arc, also just anecdotal but all the other client structs i've worked with (nats and sqlx) allow this cloning so the user doesn't need to do the Arc wrapping in their application

@khaf
Copy link
Collaborator

khaf commented May 26, 2023

I have nothing against it other than caution for the future. How does it differ ergonomically if we do that? Can you share some code?

@databasedav
Copy link
Author

databasedav commented Jun 17, 2023

the ergonomic benefit is simply not needing to wrap the client struct in an Arc in generic-specifying contexts, the examples i have are from using axum e.g. when declaring request extractors

#[async_trait]
impl<S> axum::extract::FromRequestParts<S> for Data
where
    Arc<aerospike::Client>: axum::extract::FromRef<S>,
    S: Send + Sync,
{
    type Rejection = axum::response::Response;

    async fn from_request_parts(parts: &mut http::request::Parts, state: &S) -> Result<Self, Self::Rejection> { ... }
}

in fact, because Client doesn't impl Clone, axum requires another manual impl for this to work

impl FromRef<StateWrapper> for Arc<aerospike::Client> {
    fn from_ref(state: &StateWrapper) -> Self {
        state.0.aerospike_client.clone()
    }
}

e.g. the nats and sqlx clients don't require this extra impl to use them in request extractors because they do impl Clone

edit: was wrong about the second thing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants