Struct anchor::FifoBuffer

source ·
pub struct FifoBuffer<const BUF_SIZE: usize> { /* private fields */ }
Expand description

FIFO buffer

This implements a simple FIFO buffer which can be useful when managing data to/from Anchor protocol handling. Using this is completely optional, it is provided as a convenience.

Implementations§

source§

impl<const BUF_SIZE: usize> FifoBuffer<BUF_SIZE>

source

pub const fn new() -> Self

Creates a new buffer

This is declared const, allowing it to be used even in static const contexts.

source

pub fn is_empty(&self) -> bool

Checks for buffer emptiness

source

pub fn len(&self) -> usize

Return length of currently stored buffer

source

pub fn receive_buffer(&mut self) -> &mut [u8]

Return mutable slice to the non-filled part of the buffer

source

pub fn extend(&mut self, buf: &[u8])

Append buf to the non-filled part of the buffer

Any excess will be discarded.

source

pub fn advance(&mut self, n: usize)

Moves the used cursor forward

This can be used after filling part of the non-filled buffer returned by receive_buffer.

source

pub fn data(&self) -> &[u8]

Returns the filled part of the buffer

source

pub fn pop(&mut self, n: usize)

Removes n bytes from the front of the buffer

This operation moves the used part of the buffer down in memory. This is linear in the number of bytes currently stored.

Auto Trait Implementations§

§

impl<const BUF_SIZE: usize> Freeze for FifoBuffer<BUF_SIZE>

§

impl<const BUF_SIZE: usize> RefUnwindSafe for FifoBuffer<BUF_SIZE>

§

impl<const BUF_SIZE: usize> Send for FifoBuffer<BUF_SIZE>

§

impl<const BUF_SIZE: usize> Sync for FifoBuffer<BUF_SIZE>

§

impl<const BUF_SIZE: usize> Unpin for FifoBuffer<BUF_SIZE>

§

impl<const BUF_SIZE: usize> UnwindSafe for FifoBuffer<BUF_SIZE>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

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

Performs the conversion.