Skip to content

Commit 4d10b6c

Browse files
committed
Additional docs and examples for PutPayload and PutPayloadMut
1 parent ff4618a commit 4d10b6c

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

object_store/src/payload.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,29 @@ use bytes::Bytes;
1919
use std::sync::Arc;
2020

2121
/// 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+
/// ```
2245
#[derive(Debug, Clone)]
2346
pub struct PutPayload(Arc<[Bytes]>);
2447

@@ -184,6 +207,23 @@ impl From<PutPayload> for Bytes {
184207
}
185208

186209
/// 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+
/// ```
187227
#[derive(Debug)]
188228
pub struct PutPayloadMut {
189229
len: usize,

0 commit comments

Comments
 (0)