@@ -19,6 +19,29 @@ use bytes::Bytes;
19
19
use std:: sync:: Arc ;
20
20
21
21
/// A cheaply cloneable, ordered collection of [`Bytes`]
22
+ ///
23
+ /// `PutPayload` is used to represent the body of a PUT request without having
24
+ /// to allocate a single contiguous buffer, reducing the amount of memory
25
+ /// copying required. Internally represented as an array of `Bytes` which are
26
+ /// themselves reference counted and cheap to create and append.
27
+ ///
28
+ /// See [`PutPayloadMut`] to for create `PutPayloads` incrementally
29
+ ///
30
+ /// # Examples: Creation
31
+ /// ```
32
+ /// # use bytes::Bytes;
33
+ /// # use object_store::PutPayload;
34
+ /// // create a payload from a static string
35
+ /// let payload = PutPayload::from("some data");
36
+ ///
37
+ /// // create a payload from a Vec of bytes (no copy)
38
+ /// let data: Vec<u8> = vec![1, 2, 3];
39
+ /// let payload = PutPayload::from(data);
40
+ ///
41
+ /// // create a payload from Bytes
42
+ /// let data = Bytes::from([1,2,3,]);
43
+ /// let payload = PutPayload::from(data);
44
+ /// ```
22
45
#[ derive( Debug , Clone ) ]
23
46
pub struct PutPayload ( Arc < [ Bytes ] > ) ;
24
47
@@ -184,6 +207,23 @@ impl From<PutPayload> for Bytes {
184
207
}
185
208
186
209
/// A builder for [`PutPayload`] that allocates memory in chunks
210
+ ///
211
+ /// # Examples:
212
+ /// ```
213
+ /// # use object_store::{PutPayloadMut, PutPayload};
214
+ /// // create a payload from two Vecs of bytes (no copy)
215
+ /// let mut builder = PutPayloadMut::new();
216
+ /// builder.push(vec![1, 2, 3].into());
217
+ /// builder.push(vec![4, 5, 6].into());
218
+ /// let payload: PutPayload = builder.freeze();
219
+ ///
220
+ /// // create a payload copying from slices (copy)
221
+ /// let mut builder = PutPayloadMut::new();
222
+ /// let data = [1, 2, 3, 4, 5, 6];
223
+ /// builder.extend_from_slice(&data[0..2]);
224
+ /// builder.extend_from_slice(&data[2..]);
225
+ /// let payload: PutPayload = builder.freeze();
226
+ /// ```
187
227
#[ derive( Debug ) ]
188
228
pub struct PutPayloadMut {
189
229
len : usize ,
0 commit comments