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]
impl<const N: usize> PingpongBuffer<N>
[src]pub const DEFAULT: PingpongBuffer<N>
[src]
pub const DEFAULT: PingpongBuffer<N>
[src]The default PingpongBuffer
pub fn is_half_full(&self) -> bool
[src]
pub fn is_half_full(&self) -> bool
[src]Is the actively written buffer more than half full
pub fn flush(&mut self) -> ([u8; N], usize)
[src]
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]
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]
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