Skip to content

Commit 8c10471

Browse files
committed
Fix SplitGrantR.bufs() documentation
1 parent b0f4d58 commit 8c10471

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

core/src/bbbuffer.rs

+18-8
Original file line numberDiff line numberDiff line change
@@ -992,16 +992,26 @@ 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 release only 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 of the buffer
1006+
/// let mut grant = prod.grant_max_remaining(2).unwrap();
1007+
/// grant.buf().copy_from_slice(&[7, 8]);
1008+
/// grant.commit(2);
1009+
///
1010+
/// // Obtain a split read grant and release the buffer
1011+
/// let mut grant = cons.split_read().unwrap();
1012+
/// assert_eq!(grant.bufs(), ([5, 6].as_ref(), [7, 8].as_ref()));
1013+
/// grant.release(4);
1014+
///
10051015
/// # // bbqueue test shim!
10061016
/// # }
10071017
/// #

0 commit comments

Comments
 (0)