jamesmunns / bbqueue

A SPSC, lockless, no_std, thread safe, queue, based on BipBuffers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Example for`SplitGrantR` `bufs` is incorrect

andresv opened this issue · comments

split_read() was recently added, so example for bufs() is probably copy-pasted from other method and therefore incorrect.

bbqueue/core/src/bbbuffer.rs

Lines 1078 to 1109 in 479eb3d

/// Obtain access to both inner buffers for reading
///
/// ```
/// # // bbqueue test shim!
/// # fn bbqtest() {
/// use bbqueue::{BBBuffer, consts::*};
///
/// // Create and split a new buffer of 6 elements
/// let buffer: BBBuffer<U6> = 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);
///
/// // Obtain a read grant, and copy to a buffer
/// let mut grant = cons.read().unwrap();
/// let mut buf = [0u8; 4];
/// buf.copy_from_slice(grant.buf());
/// assert_eq!(&buf, &[1, 2, 3, 4]);
/// # // bbqueue test shim!
/// # }
/// #
/// # fn main() {
/// # #[cfg(not(feature = "thumbv6"))]
/// # bbqtest();
/// # }
/// ```
pub fn bufs(&self) -> (&[u8], &[u8]) {
(self.buf1, self.buf2)
}