Struct Fifo

Source
pub struct Fifo<const L: usize, const F: usize, T> { /* private fields */ }
Expand description

Shared First-In/First-Out Buffer

§Principle

The methods on this object work by negociating how many items can be pushed or pulled based on atomic integer operations.

When you push N items, a reservation of N slots will be made in the buffer. Once the reservation is made, the items are written into the slots and they are marked as “produced”.

When you try to pull some items from the buffer, first a negociation takes place based on constraints specified by the Storage implementation you provide. If the number of available items meets these constraints, these items are extracted from the buffer.

§Fifo vs Channel

Realistically, someone would use channels instead of this. Channels provide distinct producer/consumer handles for one FIFO, which makes code easier to understand.

§Memory Footprint

  • This structure has a size of 68 bytes.
  • It has a boxed 24-byte block recycle bin.
  • The recycle bin has a growable buffer of 16-byte elements.
  • Each block as a size of 16 + F x (2 + 8 x sz(item)) bytes.

For basic uses, the overall memory footprint of this structure should be in the hundreds of bytes.

Trait Implementations§

Source§

impl<const L: usize, const F: usize, T> Default for Fifo<L, F, T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<const L: usize, const F: usize, T> FifoApi<T> for Fifo<L, F, T>

Source§

fn push(&self, iter: &mut dyn ExactSizeIterator<Item = T>)

Inserts all the items from an iterator into the FIFO, atomically

The order of the items is preserved, and they will be inserted consecutively; other pushes from other tasks will not interfere.

This method doesn’t spin, yield or sleeps; it should complete rather immediately. The only think that can take time here is an occasional memory allocation.

Source§

fn pull(&self, storage: &mut dyn InternalStorageApi<T>) -> usize

Retrieves some elements from the FIFO, atomically

If the number of available items doesn’t meet the constraints of the storage parameter, this returns zero.

This method doesn’t spin, yield or sleeps; it should complete rather immediately. The only think that can take time here is an occasional memory allocation.

Source§

fn iter(&self) -> PullIter<'_, T>

Source§

impl<const L: usize, const F: usize, T> Send for Fifo<L, F, T>

Source§

impl<const L: usize, const F: usize, T> Sync for Fifo<L, F, T>

Auto Trait Implementations§

§

impl<const L: usize, const F: usize, T> !Freeze for Fifo<L, F, T>

§

impl<const L: usize, const F: usize, T> RefUnwindSafe for Fifo<L, F, T>

§

impl<const L: usize, const F: usize, T> Unpin for Fifo<L, F, T>

§

impl<const L: usize, const F: usize, T> !UnwindSafe for Fifo<L, F, T>

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>,

Source§

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>,

Source§

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.