@@ -106,43 +106,58 @@ impl Storage {
106
106
107
107
/// A simple upload from a buffer.
108
108
///
109
+ /// # Parameters
110
+ /// * `bucket` - the bucket name containing the object. In
111
+ /// `projects/_/buckets/{bucket_id}` format.
112
+ /// * `object` - the object name.
113
+ /// * `payload` - the object data.
114
+ ///
109
115
/// # Example
110
116
/// ```
111
117
/// # use google_cloud_storage::client::Storage;
112
118
/// async fn example(client: &Storage) -> gax::Result<()> {
113
119
/// let response = client
114
- /// .insert_object()
115
- /// .set_bucket("projects/_/buckets/my-bucket")
116
- /// .set_object("my-object")
117
- /// .set_payload("the quick brown fox jumped over the lazy dog")
120
+ /// .insert_object("projects/_/buckets/my-bucket", "my-object", "the quick brown fox jumped over the lazy dog")
118
121
/// .send()
119
122
/// .await?;
120
123
/// println!("response details={response:?}");
121
124
/// Ok(())
122
125
/// }
123
126
/// ```
124
- pub fn insert_object ( & self ) -> InsertObject {
125
- InsertObject :: new ( self . inner . clone ( ) )
127
+ pub fn insert_object < B , O , P > ( & self , bucket : B , object : O , payload : P ) -> InsertObject
128
+ where
129
+ B : Into < String > ,
130
+ O : Into < String > ,
131
+ P : Into < bytes:: Bytes > ,
132
+ {
133
+ InsertObject :: new ( self . inner . clone ( ) , bucket, object, payload)
126
134
}
127
135
128
136
/// A simple download into a buffer.
129
137
///
138
+ /// # Parameters
139
+ /// * `bucket` - the bucket name containing the object. In
140
+ /// `projects/_/buckets/{bucket_id}` format.
141
+ /// * `object` - the object name.
142
+ ///
130
143
/// # Example
131
144
/// ```
132
145
/// # use google_cloud_storage::client::Storage;
133
146
/// async fn example(client: &Storage) -> gax::Result<()> {
134
147
/// let contents = client
135
- /// .read_object()
136
- /// .set_bucket("projects/_/buckets/my-bucket")
137
- /// .set_object("my-object")
148
+ /// .read_object("projects/_/buckets/my-bucket", "my-object")
138
149
/// .send()
139
150
/// .await?;
140
151
/// println!("object contents={contents:?}");
141
152
/// Ok(())
142
153
/// }
143
154
/// ```
144
- pub fn read_object ( & self ) -> ReadObject {
145
- ReadObject :: new ( self . inner . clone ( ) )
155
+ pub fn read_object < B , O > ( & self , bucket : B , object : O ) -> ReadObject
156
+ where
157
+ B : Into < String > ,
158
+ O : Into < String > ,
159
+ {
160
+ ReadObject :: new ( self . inner . clone ( ) , bucket, object)
146
161
}
147
162
148
163
pub ( crate ) async fn new (
@@ -255,12 +270,17 @@ pub struct InsertObject {
255
270
}
256
271
257
272
impl InsertObject {
258
- fn new ( inner : std:: sync:: Arc < StorageInner > ) -> Self {
273
+ fn new < B , O , P > ( inner : std:: sync:: Arc < StorageInner > , bucket : B , object : O , payload : P ) -> Self
274
+ where
275
+ B : Into < String > ,
276
+ O : Into < String > ,
277
+ P : Into < bytes:: Bytes > ,
278
+ {
259
279
InsertObject {
260
280
inner,
261
- bucket : Default :: default ( ) ,
262
- object : Default :: default ( ) ,
263
- payload : Default :: default ( ) ,
281
+ bucket : bucket . into ( ) ,
282
+ object : object . into ( ) ,
283
+ payload : payload . into ( ) ,
264
284
}
265
285
}
266
286
@@ -271,10 +291,7 @@ impl InsertObject {
271
291
/// # use google_cloud_storage::client::Storage;
272
292
/// async fn example(client: &Storage) -> gax::Result<()> {
273
293
/// let response = client
274
- /// .insert_object()
275
- /// .set_bucket("projects/_/buckets/my-bucket")
276
- /// .set_object("my-object")
277
- /// .set_payload("the quick brown fox jumped over the lazy dog")
294
+ /// .insert_object("projects/_/buckets/my-bucket", "my-object", "the quick brown fox jumped over the lazy dog")
278
295
/// .send()
279
296
/// .await?;
280
297
/// println!("response details={response:?}");
@@ -320,24 +337,6 @@ impl InsertObject {
320
337
321
338
Ok ( Object :: from ( response) )
322
339
}
323
-
324
- /// Sets the value of bucket.
325
- pub fn set_bucket < T : Into < String > > ( mut self , v : T ) -> Self {
326
- self . bucket = v. into ( ) ;
327
- self
328
- }
329
-
330
- /// Sets the value of object.
331
- pub fn set_object < T : Into < String > > ( mut self , v : T ) -> Self {
332
- self . object = v. into ( ) ;
333
- self
334
- }
335
-
336
- /// Sets the value of payload.
337
- pub fn set_payload < T : Into < bytes:: Bytes > > ( mut self , v : T ) -> Self {
338
- self . payload = v. into ( ) ;
339
- self
340
- }
341
340
}
342
341
343
342
/// The request builder for [Storage::read_object][crate::client::Storage::read_object] calls.
@@ -350,10 +349,7 @@ impl InsertObject {
350
349
/// # let client = Storage::builder()
351
350
/// # .with_endpoint("https://storage.googleapis.com")
352
351
/// # .build().await?;
353
- /// let builder: ReadObject = client
354
- /// .read_object()
355
- /// .set_bucket("projects/_/buckets/my-bucket")
356
- /// .set_object("my-object");
352
+ /// let builder: ReadObject = client.read_object("projects/_/buckets/my-bucket", "my-object");
357
353
/// let contents = builder.send().await?;
358
354
/// println!("object contents={contents:?}");
359
355
/// # Ok::<(), anyhow::Error>(()) });
@@ -364,25 +360,19 @@ pub struct ReadObject {
364
360
}
365
361
366
362
impl ReadObject {
367
- fn new ( inner : std:: sync:: Arc < StorageInner > ) -> Self {
363
+ fn new < B , O > ( inner : std:: sync:: Arc < StorageInner > , bucket : B , object : O ) -> Self
364
+ where
365
+ B : Into < String > ,
366
+ O : Into < String > ,
367
+ {
368
368
ReadObject {
369
369
inner,
370
- request : control:: model:: ReadObjectRequest :: new ( ) ,
370
+ request : control:: model:: ReadObjectRequest :: new ( )
371
+ . set_bucket ( bucket)
372
+ . set_object ( object) ,
371
373
}
372
374
}
373
375
374
- /// Sets the value of [bucket][control::model::ReadObjectRequest::bucket].
375
- pub fn set_bucket < T : Into < String > > ( mut self , v : T ) -> Self {
376
- self . request . bucket = v. into ( ) ;
377
- self
378
- }
379
-
380
- /// Sets the value of [object][control::model::ReadObjectRequest::object].
381
- pub fn set_object < T : Into < String > > ( mut self , v : T ) -> Self {
382
- self . request . object = v. into ( ) ;
383
- self
384
- }
385
-
386
376
/// Sets the value of [generation][control::model::ReadObjectRequest::generation].
387
377
pub fn set_generation < T : Into < i64 > > ( mut self , v : T ) -> Self {
388
378
self . request . generation = v. into ( ) ;
@@ -576,9 +566,7 @@ mod tests {
576
566
. await ?;
577
567
578
568
let read_object_builder = client
579
- . read_object ( )
580
- . set_bucket ( "projects/_/buckets/bucket" )
581
- . set_object ( "object" )
569
+ . read_object ( "projects/_/buckets/bucket" , "object" )
582
570
. http_request_builder ( )
583
571
. await ?
584
572
. build ( ) ?;
@@ -600,9 +588,7 @@ mod tests {
600
588
. await ?;
601
589
602
590
client
603
- . read_object ( )
604
- . set_bucket ( "projects/_/buckets/bucket" )
605
- . set_object ( "object" )
591
+ . read_object ( "projects/_/buckets/bucket" , "object" )
606
592
. http_request_builder ( )
607
593
. await
608
594
. inspect_err ( |e| assert ! ( e. is_authentication( ) ) )
@@ -618,9 +604,7 @@ mod tests {
618
604
. await ?;
619
605
620
606
client
621
- . read_object ( )
622
- . set_bucket ( "malformed" )
623
- . set_object ( "object" )
607
+ . read_object ( "malformed" , "object" )
624
608
. http_request_builder ( )
625
609
. await
626
610
. expect_err ( "malformed bucket string should error" ) ;
@@ -635,9 +619,7 @@ mod tests {
635
619
. await ?;
636
620
637
621
let read_object_builder = client
638
- . read_object ( )
639
- . set_bucket ( "projects/_/buckets/bucket" )
640
- . set_object ( "object" )
622
+ . read_object ( "projects/_/buckets/bucket" , "object" )
641
623
. set_generation ( 5 )
642
624
. set_if_generation_match ( 10 )
643
625
. set_if_generation_not_match ( 20 )
0 commit comments