[−][src]Struct bbqueue::GrantR
A structure representing a contiguous region of memory that may be read from, and potentially "released" (or cleared) from the queue
NOTE: If the grant is dropped without explicitly releasing
the contents, then no bytes will be released as read.
If the thumbv6
feature is selected, dropping the grant
without releasing it takes a short critical section,
Implementations
impl<'a, N> GrantR<'a, N> where
N: ArrayLength<u8>,
[src]
N: ArrayLength<u8>,
pub fn release(self, used: usize)
[src]
Release a sequence of bytes from the buffer, allowing the space to be used by later writes. This consumes the grant.
If used
is larger than the given grant, the full grant will
be released.
NOTE: If the thumbv6
feature is selected, this function takes a short critical
section while releasing.
pub fn buf(&self) -> &[u8]
[src]
Obtain access to the inner buffer for reading
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]);
pub unsafe fn as_static_buf(&self) -> &'static [u8]
[src]
Sometimes, it's not possible for the lifetimes to check out. For example,
if you need to hand this buffer to a function that expects to receive a
&'static [u8]
, it is not possible for the inner reference to outlive the
grant itself.
You MUST guarantee that in no cases, the reference that is returned here outlives the grant itself. Once the grant has been released, referencing the data contained WILL cause undefined behavior.
Additionally, you must ensure that a separate reference to this data is not created
to this data, e.g. using Deref
or the buf()
method of this grant.
Trait Implementations
impl<'a, N: Debug> Debug for GrantR<'a, N> where
N: ArrayLength<u8>,
[src]
N: ArrayLength<u8>,
impl<'a, N> Deref for GrantR<'a, N> where
N: ArrayLength<u8>,
[src]
N: ArrayLength<u8>,
impl<'a, N> Drop for GrantR<'a, N> where
N: ArrayLength<u8>,
[src]
N: ArrayLength<u8>,
impl<'a, N: PartialEq> PartialEq<GrantR<'a, N>> for GrantR<'a, N> where
N: ArrayLength<u8>,
[src]
N: ArrayLength<u8>,
impl<'a, N> Send for GrantR<'a, N> where
N: ArrayLength<u8>,
[src]
N: ArrayLength<u8>,
impl<'a, N> StructuralPartialEq for GrantR<'a, N> where
N: ArrayLength<u8>,
[src]
N: ArrayLength<u8>,
Auto Trait Implementations
impl<'a, N> !RefUnwindSafe for GrantR<'a, N>
impl<'a, N> !Sync for GrantR<'a, N>
impl<'a, N> Unpin for GrantR<'a, N>
impl<'a, N> !UnwindSafe for GrantR<'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>,