Skip to content

Commit

Permalink
Fix SplitGrantR.bufs() documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Sympatron committed Dec 9, 2024
1 parent b0f4d58 commit 8c10471
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions core/src/bbbuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -992,16 +992,26 @@ 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 release only 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
/// 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

0 comments on commit 8c10471

Please sign in to comment.