Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SplitGrantR.bufs() documentation #108

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions core/src/bbbuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -992,16 +992,27 @@ impl<'a, const N: usize> SplitGrantR<'a, N> {
/// let buffer: BBBuffer<6> = BBBuffer::new();
/// let (mut prod, mut cons) = buffer.try_split().unwrap();
///
/// // Successfully obtain and commit a grant of four bytes
/// let mut grant = prod.grant_max_remaining(4).unwrap();
/// grant.buf().copy_from_slice(&[1, 2, 3, 4]);
/// grant.commit(4);
/// // Successfully obtain and commit a grant of six bytes filling the buffer
/// let mut grant = prod.grant_max_remaining(6).unwrap();
/// grant.buf().copy_from_slice(&[1, 2, 3, 4, 5, 6]);
/// grant.commit(6);
///
/// // Obtain a read grant, and copy to a buffer
/// // Obtain a read grant of all six bytes, but only release four bytes
/// let mut grant = cons.read().unwrap();
/// let mut buf = [0u8; 4];
/// buf.copy_from_slice(grant.buf());
/// assert_eq!(&buf, &[1, 2, 3, 4]);
/// assert_eq!(grant.buf(), &[1, 2, 3, 4, 5, 6]);
/// grant.release(4);
///
/// // Successfully obtain and commit a grant of two bytes again at the start
/// // of the buffer creating a split buffer
/// let mut grant = prod.grant_max_remaining(2).unwrap();
/// grant.buf().copy_from_slice(&[7, 8]);
/// grant.commit(2);
///
/// // Obtain a split read grant and release the buffer
/// let mut grant = cons.split_read().unwrap();
/// assert_eq!(grant.bufs(), ([5, 6].as_ref(), [7, 8].as_ref()));
/// grant.release(4);
///
/// # // bbqueue test shim!
/// # }
/// #
Expand Down
Loading