[−][src]Struct bbqueue::cm_mutex::Producer
Producer
is the primary interface for pushing data into a BBBuffer
.
There are various methods for obtaining a grant to write to the buffer, with
different potential tradeoffs. As all grants are required to be a contiguous
range of data, different strategies are sometimes useful when making the decision
between maximizing usage of the buffer, and ensuring a given grant is successful.
As a short summary of currently possible grants:
grant_exact(N)
- User will receive a grant
sz == N
(or receive an error) - This may cause a wraparound if a grant of size N is not available at the end of the ring.
- If this grant caused a wraparound, the bytes that were "skipped" at the end of the ring will not be available until the reader reaches them, regardless of whether the grant commited any data or not.
- Maximum possible waste due to skipping:
N - 1
bytes
- User will receive a grant
grant_max_remaining(N)
- User will receive a grant
0 < sz <= N
(or receive an error) - This will only cause a wrap to the beginning of the ring if exactly zero bytes are available at the end of the ring.
- Maximum possible waste due to skipping: 0 bytes
- User will receive a grant
See this github issue for a discussion of grant methods that could be added in the future.
Methods
impl<'a, N> Producer<'a, N> where
N: ArrayLength<u8>,
[src]
N: ArrayLength<u8>,
pub fn grant_exact(&mut self, sz: usize) -> Result<GrantW<'a, N>>
[src]
Request a writable, contiguous section of memory of exactly
sz
bytes. If the buffer size requested is not available,
an error will be returned.
This method may cause the buffer to wrap around early if the requested space is not available at the end of the buffer, but is available at the beginning
use bbqueue::{BBBuffer, consts::*}; // Create and split a new buffer of 6 elements let buffer: BBBuffer<U6> = BBBuffer::new(); let (mut prod, cons) = buffer.try_split().unwrap(); // Successfully obtain and commit a grant of four bytes let mut grant = prod.grant_exact(4).unwrap(); assert_eq!(grant.buf().len(), 4); grant.commit(4); // Try to obtain a grant of three bytes assert!(prod.grant_exact(3).is_err());
pub fn grant_max_remaining(&mut self, sz: usize) -> Result<GrantW<'a, N>>
[src]
Request a writable, contiguous section of memory of up to
sz
bytes. If a buffer of size sz
is not available without
wrapping, but some space (0 < available < sz) is available without
wrapping, then a grant will be given for the remaining size at the
end of the buffer. If no space is available for writing, an error
will be returned.
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(); assert_eq!(grant.buf().len(), 4); grant.commit(4); // Release the four initial commited bytes let mut grant = cons.read().unwrap(); assert_eq!(grant.buf().len(), 4); grant.release(4); // Try to obtain a grant of three bytes, get two bytes let mut grant = prod.grant_max_remaining(3).unwrap(); assert_eq!(grant.buf().len(), 2); grant.commit(2);
Trait Implementations
impl<'a, N> Send for Producer<'a, N> where
N: ArrayLength<u8>,
[src]
N: ArrayLength<u8>,
Auto Trait Implementations
impl<'a, N> !RefUnwindSafe for Producer<'a, N>
impl<'a, N> !Sync for Producer<'a, N>
impl<'a, N> Unpin for Producer<'a, N>
impl<'a, N> !UnwindSafe for Producer<'a, N>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,