From e53e151e3e9858ae392af511c237baa5998dec50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20P=C3=BCtz?= Date: Mon, 16 Jun 2025 14:48:16 +0200 Subject: [PATCH] fix: replace Arc> credential-provider with Arc<...> (#164) * replace Arc> provider with Arc<...> * remove need for caller to Box provider --- common/src/test_context.rs | 4 ++-- examples/common.rs | 4 ++-- examples/object_prompt.rs | 2 +- examples/put_object.rs | 2 +- src/s3/client.rs | 19 ++++++++----------- 5 files changed, 14 insertions(+), 17 deletions(-) diff --git a/common/src/test_context.rs b/common/src/test_context.rs index db25213..5a0c5bd 100644 --- a/common/src/test_context.rs +++ b/common/src/test_context.rs @@ -59,7 +59,7 @@ impl TestContext { let static_provider = StaticProvider::new(&access_key, &secret_key, None); let client = Client::new( base_url.clone(), - Some(Box::new(static_provider)), + Some(static_provider), ssl_cert_file, Some(ignore_cert_check), ) @@ -116,7 +116,7 @@ impl TestContext { let static_provider = StaticProvider::new(&access_key, &secret_key, None); let client = Client::new( base_url.clone(), - Some(Box::new(static_provider)), + Some(static_provider), Some(&*ssl_cert_file), Some(ignore_cert_check), ) diff --git a/examples/common.rs b/examples/common.rs index 1d3ad44..ace1994 100644 --- a/examples/common.rs +++ b/examples/common.rs @@ -16,7 +16,7 @@ pub fn create_client_on_play() -> Result Result Result<(), Box> { let static_provider = StaticProvider::new("admin", "admin", None); let client = ClientBuilder::new(base_url.clone()) - .provider(Some(Box::new(static_provider))) + .provider(Some(static_provider)) .ignore_cert_check(Some(true)) .build()?; diff --git a/examples/put_object.rs b/examples/put_object.rs index 32aa74e..ec44391 100644 --- a/examples/put_object.rs +++ b/examples/put_object.rs @@ -42,7 +42,7 @@ async fn main() -> Result<(), Box> { ); let client: Client = ClientBuilder::new("https://play.min.io".parse()?) - .provider(Some(Box::new(static_provider))) + .provider(Some(static_provider)) .build()?; let resp: BucketExistsResponse = client.bucket_exists(&args.bucket).send().await.unwrap(); diff --git a/src/s3/client.rs b/src/s3/client.rs index a1f3801..69f1a1f 100644 --- a/src/s3/client.rs +++ b/src/s3/client.rs @@ -123,7 +123,7 @@ pub const MAX_MULTIPART_COUNT: u16 = 10_000; #[derive(Debug, Default)] pub struct ClientBuilder { base_url: BaseUrl, - provider: Option>>, + provider: Option>, ssl_cert_file: Option, ignore_cert_check: Option, app_info: Option<(String, String)>, @@ -139,12 +139,9 @@ impl ClientBuilder { } } - /// Set the credential provider. If not set anonymous access is used. - pub fn provider( - mut self, - provider: Option>, - ) -> Self { - self.provider = provider.map(Arc::new); + /// Set the credential provider. If not, set anonymous access is used. + pub fn provider(mut self, provider: Option

) -> Self { + self.provider = provider.map(|p| Arc::new(p) as Arc); self } @@ -245,11 +242,11 @@ impl Client { /// "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", /// None, /// ); - /// let client = Client::new(base_url, Some(Box::new(static_provider)), None, None).unwrap(); + /// let client = Client::new(base_url, Some(static_provider), None, None).unwrap(); /// ``` - pub fn new( + pub fn new( base_url: BaseUrl, - provider: Option>, + provider: Option

, ssl_cert_file: Option<&Path>, ignore_cert_check: Option, ) -> Result { @@ -615,7 +612,7 @@ impl Client { #[derive(Clone, Debug, Default)] pub(crate) struct SharedClientItems { pub(crate) base_url: BaseUrl, - pub(crate) provider: Option>>, + pub(crate) provider: Option>, region_map: DashMap, express: OnceLock, }