yoshidan / google-cloud-rust

Google Cloud Client Libraries for Rust.
MIT License
222 stars 80 forks source link

Wouldn't it make sense for the Storage Client to be clonable? #134

Closed open-schnick closed 1 year ago

open-schnick commented 1 year ago

Currently the Storage Client is not clone. It also cannot be derived directly because ServiceAccountClient is also not clone Can we derive that on these two structs or does that introduce sideeffects? I would imagine that duplicating the ServiceAccountClient means duplicating the authentication logic. Thoughts @yoshidan?

yoshidan commented 1 year ago

Since the Client and its children have not a few fields, for example, I think the allocation load to Clone for each request may be large. Currently, though, we would use Arc as follows,

let client = Arc::new(client)
let client_per_each_request = client.clone()

I think it would be nice to have Arc inside as well as other components.

#[derive(Clone)]
pub struct Client {
    inner: Arc<InternalClient>
}

struct InternalClient {
    default_google_access_id: Option<String>,
    default_sign_by: Option<SignBy>,
    storage_client: StorageClient, default_account_client: Option<String>,
    service_account_client: ServiceAccountClient
}
open-schnick commented 1 year ago

Sorry for the late response, I wrapped the Client myself in an Arc. Thanks for your feedback :)