[][src]Struct bbqueue_ng::GrantR

pub struct GrantR<'a, const N: usize> { /* fields omitted */ }

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, or by setting the number of bytes to automatically be released with to_release(), 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, const N: usize> GrantR<'a, { N }>[src]

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_ng::BBBuffer;

// Create and split a new buffer of 6 elements
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);

// 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 fn buf_mut(&mut self) -> &mut [u8][src]

Obtain mutable access to the read grant

This is useful if you are performing in-place operations on an incoming packet, such as decryption

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.

pub fn to_release(&mut self, amt: usize)[src]

Configures the amount of bytes to be released on drop.

Trait Implementations

impl<'a, const N: usize> Debug for GrantR<'a, N>[src]

impl<'a, const N: usize> Deref for GrantR<'a, N>[src]

type Target = [u8]

The resulting type after dereferencing.

impl<'a, const N: usize> DerefMut for GrantR<'a, N>[src]

impl<'a, const N: usize> Drop for GrantR<'a, N>[src]

impl<'a, const N: usize> PartialEq<GrantR<'a, N>> for GrantR<'a, N>[src]

impl<'a, const N: usize> Send for GrantR<'a, { N }>[src]

impl<'a, const N: usize> StructuralPartialEq for GrantR<'a, N>[src]

Auto Trait Implementations

impl<'a, const N: usize> !Sync for GrantR<'a, N>[src]

impl<'a, const N: usize> Unpin for GrantR<'a, N>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

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]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.