Skip to content

Commit 443e78f

Browse files
committed
Fix SplitGrantR.bufs() documentation
1 parent b0f4d58 commit 443e78f

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

core/src/bbbuffer.rs

+19-8
Original file line numberDiff line numberDiff line change
@@ -992,16 +992,27 @@ impl<'a, const N: usize> SplitGrantR<'a, N> {
992992
/// let buffer: BBBuffer<6> = BBBuffer::new();
993993
/// let (mut prod, mut cons) = buffer.try_split().unwrap();
994994
///
995-
/// // Successfully obtain and commit a grant of four bytes
996-
/// let mut grant = prod.grant_max_remaining(4).unwrap();
997-
/// grant.buf().copy_from_slice(&[1, 2, 3, 4]);
998-
/// grant.commit(4);
995+
/// // Successfully obtain and commit a grant of six bytes filling the buffer
996+
/// let mut grant = prod.grant_max_remaining(6).unwrap();
997+
/// grant.buf().copy_from_slice(&[1, 2, 3, 4, 5, 6]);
998+
/// grant.commit(6);
999999
///
1000-
/// // Obtain a read grant, and copy to a buffer
1000+
/// // Obtain a read grant of all six bytes, but only release four bytes
10011001
/// let mut grant = cons.read().unwrap();
1002-
/// let mut buf = [0u8; 4];
1003-
/// buf.copy_from_slice(grant.buf());
1004-
/// assert_eq!(&buf, &[1, 2, 3, 4]);
1002+
/// assert_eq!(grant.buf(), &[1, 2, 3, 4, 5, 6]);
1003+
/// grant.release(4);
1004+
///
1005+
/// // Successfully obtain and commit a grant of two bytes again at the start
1006+
/// // of the buffer creating a split buffer
1007+
/// let mut grant = prod.grant_max_remaining(2).unwrap();
1008+
/// grant.buf().copy_from_slice(&[7, 8]);
1009+
/// grant.commit(2);
1010+
///
1011+
/// // Obtain a split read grant and release the buffer
1012+
/// let mut grant = cons.split_read().unwrap();
1013+
/// assert_eq!(grant.bufs(), ([5, 6].as_ref(), [7, 8].as_ref()));
1014+
/// grant.release(4);
1015+
///
10051016
/// # // bbqueue test shim!
10061017
/// # }
10071018
/// #

0 commit comments

Comments
 (0)