Struct pingpong::PingpongBuffer[][src]

pub struct PingpongBuffer<const N: usize> { /* fields omitted */ }
Expand description

Pingpong or double buffering is useful for performing buffering tasks that require similtaneous reading and writing. While one buffer is being written to, the other can be read from and visa versa. In this implementation, the buffer that is being written to is known as the “active” buffer and the buffer being read from is the “reserve” buffer

Implementations

impl<const N: usize> PingpongBuffer<N>[src]

pub const DEFAULT: PingpongBuffer<N>[src]

The default PingpongBuffer

pub fn is_empty(&self) -> bool[src]

Is the actively written buffer empty

pub fn is_half_full(&self) -> bool[src]

Is the actively written buffer more than half full

pub fn clear(&mut self)[src]

Clears the Pingpong buffer to return it back into its default state

pub fn flush(&mut self) -> ([u8; N], usize)[src]

Read out the remainding data from the active buffer Useful in circumstances in which the buffering process needs to end, and there isnt enough data to toggle between the active and reserve buffers

pub fn read(&mut self) -> Option<&[u8; N]>[src]

Read the data from the reserve buffer. If the reserve buffer is not yet full, this function will return Option::None Once the bytes are read from, this will allow the reserve buffer to be toggled into the active buffer

pub fn append(&mut self, data: &[u8]) -> bool[src]

Append data to the active buffer If the active buffer fills to maximum capacity, then the active and reserve buffers are switched, allowing the remainding data to be written to the reserve (now active) buffer This switch can only happen if the data in the reserve buffer has been successfully read

Auto Trait Implementations

impl<const N: usize> Send for PingpongBuffer<N>

impl<const N: usize> Sync for PingpongBuffer<N>

impl<const N: usize> Unpin for PingpongBuffer<N>

Blanket Implementations

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

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

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.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

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.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.