Skip to content

Commit ca79393

Browse files
committed
updated clients: added Into<String>in API
1 parent 2b37a27 commit ca79393

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+261
-218
lines changed

common/src/cleanup_guard.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ pub struct CleanupGuard {
2626

2727
impl CleanupGuard {
2828
#[allow(dead_code)]
29-
pub fn new(client: &Client, bucket_name: &str) -> Self {
29+
pub fn new<S: Into<String>>(client: Client, bucket_name: S) -> Self {
3030
Self {
31-
client: client.clone(),
32-
bucket_name: bucket_name.to_string(),
31+
client,
32+
bucket_name: bucket_name.into(),
3333
}
3434
}
3535
}

common/src/test_context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl TestContext {
152152
pub async fn create_bucket_helper(&self) -> (String, CleanupGuard) {
153153
let bucket_name = rand_bucket_name();
154154
let _resp = self.client.make_bucket(&bucket_name).send().await.unwrap();
155-
let guard = CleanupGuard::new(&self.client, &bucket_name);
155+
let guard = CleanupGuard::new(self.client.clone(), &bucket_name);
156156
(bucket_name, guard)
157157
}
158158
}

examples/object_prompt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
6767
);
6868

6969
let resp: ObjectPromptResponse = client
70-
.object_prompt(&bucket_name, &object_name, "what is it about?".into())
70+
.object_prompt(bucket_name, object_name, "what is it about?")
7171
//.lambda_arn("arn:minio:s3-object-lambda::_:webhook") // this is the default value
7272
.send()
7373
.await?;

src/s3/builders/append_object.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ pub struct AppendObject {
4747

4848
impl AppendObject {
4949
pub fn new(
50-
client: &Client,
50+
client: Client,
5151
bucket: String,
5252
object: String,
5353
data: SegmentedBytes,
5454
offset_bytes: u64,
5555
) -> Self {
5656
Self {
57-
client: client.clone(),
57+
client,
5858
bucket,
5959
object,
6060
offset_bytes,
@@ -134,13 +134,13 @@ pub struct AppendObjectContent {
134134

135135
impl AppendObjectContent {
136136
pub fn new(
137-
client: &Client,
137+
client: Client,
138138
bucket: String,
139139
object: String,
140140
content: impl Into<ObjectContent>,
141141
) -> Self {
142142
Self {
143-
client: client.clone(),
143+
client,
144144
bucket,
145145
object,
146146
input_content: content.into(),

src/s3/builders/copy_object.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ pub struct UploadPartCopy {
4848
}
4949

5050
impl UploadPartCopy {
51-
pub fn new(client: &Client, bucket: String, object: String, upload_id: String) -> Self {
51+
pub fn new(client: Client, bucket: String, object: String, upload_id: String) -> Self {
5252
Self {
53-
client: client.clone(),
53+
client,
5454
bucket,
5555
object,
5656
upload_id,
@@ -144,9 +144,9 @@ pub struct CopyObjectInternal {
144144
}
145145

146146
impl CopyObjectInternal {
147-
pub fn new(client: &Client, bucket: String, object: String) -> Self {
147+
pub fn new(client: Client, bucket: String, object: String) -> Self {
148148
Self {
149-
client: client.clone(),
149+
client,
150150
bucket,
151151
object,
152152
..Default::default()
@@ -347,9 +347,9 @@ pub struct CopyObject {
347347
}
348348

349349
impl CopyObject {
350-
pub fn new(client: &Client, bucket: String, object: String) -> Self {
350+
pub fn new(client: Client, bucket: String, object: String) -> Self {
351351
Self {
352-
client: client.clone(),
352+
client,
353353
bucket,
354354
object,
355355
..Default::default()
@@ -553,9 +553,9 @@ pub struct ComposeObjectInternal {
553553
}
554554

555555
impl ComposeObjectInternal {
556-
pub fn new(client: &Client, bucket: String, object: String) -> Self {
556+
pub fn new(client: Client, bucket: String, object: String) -> Self {
557557
Self {
558-
client: client.clone(),
558+
client,
559559
bucket,
560560
object,
561561
..Default::default()
@@ -826,9 +826,9 @@ pub struct ComposeObject {
826826
}
827827

828828
impl ComposeObject {
829-
pub fn new(client: &Client, bucket: String, object: String) -> Self {
829+
pub fn new(client: Client, bucket: String, object: String) -> Self {
830830
Self {
831-
client: client.clone(),
831+
client,
832832
bucket,
833833
object,
834834
..Default::default()

src/s3/builders/delete_object_tags.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ pub struct DeleteObjectTags {
3636
}
3737

3838
impl DeleteObjectTags {
39-
pub fn new(client: &Client, bucket: String, object: String) -> Self {
39+
pub fn new(client: Client, bucket: String, object: String) -> Self {
4040
Self {
41-
client: client.clone(),
41+
client,
4242
bucket,
4343
object,
4444
..Default::default()

src/s3/builders/disable_object_legal_hold.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ pub struct DisableObjectLegalHold {
3838
}
3939

4040
impl DisableObjectLegalHold {
41-
pub fn new(client: &Client, bucket: String, object: String) -> Self {
41+
pub fn new(client: Client, bucket: String, object: String) -> Self {
4242
Self {
43-
client: client.clone(),
43+
client,
4444
bucket,
4545
object,
4646
..Default::default()

src/s3/builders/enable_object_legal_hold.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ pub struct EnableObjectLegalHold {
3838
}
3939

4040
impl EnableObjectLegalHold {
41-
pub fn new(client: &Client, bucket: String, object: String) -> Self {
41+
pub fn new(client: Client, bucket: String, object: String) -> Self {
4242
Self {
43-
client: client.clone(),
43+
client,
4444
bucket,
4545
object,
4646
..Default::default()

src/s3/builders/get_region.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ pub struct GetRegion {
3333
}
3434

3535
impl GetRegion {
36-
pub fn new(client: &Client, bucket: String) -> Self {
36+
pub fn new(client: Client, bucket: String) -> Self {
3737
Self {
38-
client: client.clone(),
38+
client,
3939
bucket,
4040
..Default::default()
4141
}

src/s3/builders/put_object.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ pub struct CreateMultipartUpload {
5757
}
5858

5959
impl CreateMultipartUpload {
60-
pub fn new(client: &Client, bucket: String, object: String) -> Self {
60+
pub fn new(client: Client, bucket: String, object: String) -> Self {
6161
CreateMultipartUpload {
62-
client: client.clone(),
62+
client,
6363
bucket,
6464
object,
6565
..Default::default()
@@ -161,9 +161,9 @@ pub struct AbortMultipartUpload {
161161
}
162162

163163
impl AbortMultipartUpload {
164-
pub fn new(client: &Client, bucket: String, object: String, upload_id: String) -> Self {
164+
pub fn new(client: Client, bucket: String, object: String, upload_id: String) -> Self {
165165
Self {
166-
client: client.clone(),
166+
client,
167167
bucket,
168168
object,
169169
upload_id,
@@ -235,14 +235,14 @@ impl S3Api for CompleteMultipartUpload {
235235

236236
impl CompleteMultipartUpload {
237237
pub fn new(
238-
client: &Client,
238+
client: Client,
239239
bucket: String,
240240
object: String,
241241
upload_id: String,
242242
parts: Vec<PartInfo>,
243243
) -> Self {
244244
Self {
245-
client: client.clone(),
245+
client,
246246
bucket,
247247
object,
248248
upload_id,
@@ -345,15 +345,15 @@ pub struct UploadPart {
345345

346346
impl UploadPart {
347347
pub fn new(
348-
client: &Client,
348+
client: Client,
349349
bucket: String,
350350
object: String,
351351
upload_id: String,
352352
part_number: u16,
353353
data: SegmentedBytes,
354354
) -> Self {
355355
Self {
356-
client: client.clone(),
356+
client,
357357
bucket,
358358
object,
359359
upload_id: Some(upload_id),
@@ -556,13 +556,13 @@ pub struct PutObjectContent {
556556

557557
impl PutObjectContent {
558558
pub fn new(
559-
client: &Client,
559+
client: Client,
560560
bucket: String,
561561
object: String,
562562
content: impl Into<ObjectContent>,
563563
) -> Self {
564564
Self {
565-
client: client.clone(),
565+
client,
566566
bucket,
567567
object,
568568
input_content: content.into(),
@@ -738,7 +738,7 @@ impl PutObjectContent {
738738
if mpu_res.is_err() {
739739
// If we failed to complete the multipart upload, we should abort it.
740740
let _ =
741-
AbortMultipartUpload::new(&client, bucket, object, create_mpu_resp.upload_id)
741+
AbortMultipartUpload::new(client, bucket, object, create_mpu_resp.upload_id)
742742
.send()
743743
.await;
744744
}

src/s3/builders/remove_objects.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,10 @@ pub struct RemoveObjectsApi {
180180
}
181181

182182
impl RemoveObjectsApi {
183-
pub fn new(client: &Client, bucket: String, objects: Vec<ObjectToDelete>) -> Self {
183+
#[inline]
184+
pub fn new(client: Client, bucket: String, objects: Vec<ObjectToDelete>) -> Self {
184185
RemoveObjectsApi {
185-
client: client.clone(),
186+
client,
186187
bucket,
187188
objects,
188189
..Default::default()
@@ -366,7 +367,7 @@ impl RemoveObjects {
366367
}
367368

368369
Ok(Some(
369-
RemoveObjectsApi::new(&self.client, self.bucket.clone(), objects)
370+
RemoveObjectsApi::new(self.client.clone(), self.bucket.clone(), objects)
370371
.bypass_governance_mode(self.bypass_governance_mode)
371372
.verbose_mode(self.verbose_mode)
372373
.extra_headers(self.extra_headers.clone())

src/s3/client/append_object.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ impl Client {
2525
/// This is a lower-level API that performs a non-multipart object upload.
2626
///
2727
/// 🛈 This operation is not supported for regular non-express buckets.
28-
pub fn append_object(
28+
pub fn append_object<S: Into<String>>(
2929
&self,
30-
bucket: &str,
31-
object: &str,
30+
bucket: S,
31+
object: S,
3232
data: SegmentedBytes,
3333
offset_bytes: u64,
3434
) -> AppendObject {
3535
AppendObject::new(
36-
self,
37-
bucket.to_owned(),
38-
object.to_owned(),
36+
self.clone(),
37+
bucket.into(),
38+
object.into(),
3939
data,
4040
offset_bytes,
4141
)
@@ -44,12 +44,12 @@ impl Client {
4444
/// Creates an AppendObjectContent request builder to append data to the end of an existing
4545
/// object. The content is streamed and appended to MinIO/S3. This is a higher-level API that
4646
/// handles multipart appends transparently.
47-
pub fn append_object_content(
47+
pub fn append_object_content<S: Into<String>, C: Into<ObjectContent>>(
4848
&self,
49-
bucket: &str,
50-
object: &str,
51-
content: impl Into<ObjectContent>,
49+
bucket: S,
50+
object: S,
51+
content: C,
5252
) -> AppendObjectContent {
53-
AppendObjectContent::new(self, bucket.to_owned(), object.to_owned(), content)
53+
AppendObjectContent::new(self.clone(), bucket.into(), object.into(), content)
5454
}
5555
}

src/s3/client/bucket_exists.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl Client {
4040
/// println!("bucket '{}' exists: {}", resp.bucket, resp.exists);
4141
/// }
4242
/// ```
43-
pub fn bucket_exists(&self, bucket: &str) -> BucketExists {
44-
BucketExists::new(self.clone(), bucket.to_owned())
43+
pub fn bucket_exists<S: Into<String>>(&self, bucket: S) -> BucketExists {
44+
BucketExists::new(self.clone(), bucket.into())
4545
}
4646
}

src/s3/client/copy_object.rs

+23-19
Original file line numberDiff line numberDiff line change
@@ -23,43 +23,47 @@ use crate::s3::builders::{
2323

2424
impl Client {
2525
/// Executes [UploadPartCopy](https://docs.aws.amazon.com/AmazonS3/latest/API/API_UploadPartCopy.html) S3 API
26-
pub fn upload_part_copy(&self, bucket: &str, object: &str, upload_id: &str) -> UploadPartCopy {
27-
UploadPartCopy::new(
28-
self,
29-
bucket.to_owned(),
30-
object.to_owned(),
31-
upload_id.to_owned(),
32-
)
26+
pub fn upload_part_copy<S: Into<String>>(
27+
&self,
28+
bucket: S,
29+
object: S,
30+
upload_id: S,
31+
) -> UploadPartCopy {
32+
UploadPartCopy::new(self.clone(), bucket.into(), object.into(), upload_id.into())
3333
}
3434

3535
/// Create a CopyObject request builder. This is a lower-level API that
3636
/// performs a non-multipart object copy.
37-
pub fn copy_object_internal(&self, bucket: &str, object: &str) -> CopyObjectInternal {
38-
CopyObjectInternal::new(self, bucket.to_owned(), object.to_owned())
37+
pub fn copy_object_internal<S: Into<String>>(
38+
&self,
39+
bucket: S,
40+
object: S,
41+
) -> CopyObjectInternal {
42+
CopyObjectInternal::new(self.clone(), bucket.into(), object.into())
3943
}
4044

4145
/// copy object is a high-order API that calls [`stat_object`] and based on the results calls
4246
/// either [`compose_object`] or [`copy_object_internal`] to copy the object.
43-
pub fn copy_object(&self, bucket: &str, object: &str) -> CopyObject {
44-
CopyObject::new(self, bucket.to_owned(), object.to_owned())
47+
pub fn copy_object<S: Into<String>>(&self, bucket: S, object: S) -> CopyObject {
48+
CopyObject::new(self.clone(), bucket.into(), object.into())
4549
}
4650

47-
pub(crate) fn compose_object_internal(
51+
pub(crate) fn compose_object_internal<S: Into<String>>(
4852
&self,
49-
bucket: &str,
50-
object: &str,
53+
bucket: S,
54+
object: S,
5155
) -> ComposeObjectInternal {
52-
ComposeObjectInternal::new(self, bucket.to_owned(), object.to_owned())
56+
ComposeObjectInternal::new(self.clone(), bucket.into(), object.into())
5357
}
5458

5559
/// compose object is high-order API that calls [`compose_object_internal`] and if that call fails,
5660
/// it calls ['abort_multipart_upload`].
57-
pub fn compose_object(
61+
pub fn compose_object<S: Into<String>>(
5862
&self,
59-
bucket: &str,
60-
object: &str,
63+
bucket: S,
64+
object: S,
6165
sources: Vec<ComposeSource>,
6266
) -> ComposeObject {
63-
ComposeObject::new(self, bucket.to_owned(), object.to_owned()).sources(sources)
67+
ComposeObject::new(self.clone(), bucket.into(), object.into()).sources(sources)
6468
}
6569
}

0 commit comments

Comments
 (0)