Struct stack_dst::fifo::Fifo

source ·
pub struct Fifo<T: ?Sized, D: DataBuf> { /* private fields */ }
Expand description

A First-In-First-Out queue of DSTs

let mut queue = ::stack_dst::Fifo::<str, ::stack_dst::buffers::Ptr8>::new();
queue.push_back_str("Hello");
queue.push_back_str("World");
assert_eq!(queue.pop_front().as_ref().map(|v| &v[..]), Some("Hello"));

Implementations§

source§

impl<T: ?Sized, D: DataBuf> Fifo<T, D>

source

pub fn new() -> Selfwhere D: Default,

Construct a new (empty) list

source

pub fn with_buffer(data: D) -> Self

Construct a new (empty) list using the provided buffer

source

pub fn push_back<U: Unsize<T>>(&mut self, v: U) -> Result<(), U>where (U, D::Inner): AlignmentValid,

Push a value at the top of the stack

source

pub fn push_back_stable<U, F: FnOnce(&U) -> &T>( &mut self, v: U, f: F ) -> Result<(), U>where (U, D::Inner): AlignmentValid,

Push a value to the end of the list (without using Unsize)

source

pub fn compact(&mut self)

Compact the list (moving the read position to zero)

source

pub fn empty(&self) -> bool

Checks if the queue is currently empty

source

pub fn pop_front(&mut self) -> Option<PopHandle<'_, T, D>>

Remove an item from the front of the list

source

pub fn front_mut(&mut self) -> Option<&mut T>

Peek the front of the queue

source

pub fn front(&self) -> Option<&T>

Peek the front of the queue

source

pub fn iter(&self) -> Iter<'_, T, D>

Obtain an immutable iterator (yields references to items, in insertion order)

let mut list = ::stack_dst::Fifo::<str, ::stack_dst::buffers::Ptr8>::new();
list.push_back_str("Hello");
list.push_back_str("world");
let mut it = list.iter();
assert_eq!(it.next(), Some("Hello"));
assert_eq!(it.next(), Some("world"));
assert_eq!(it.next(), None);
source

pub fn iter_mut(&mut self) -> IterMut<'_, T, D>

Obtain a mutable iterator

let mut list = ::stack_dst::Fifo::<[u8], ::stack_dst::buffers::Ptr8>::new();
list.push_copied(&[1,2,3]);
list.push_copied(&[9]);
for v in list.iter_mut() {
    v[0] -= 1;
}
let mut it = list.iter();
assert_eq!(it.next(), Some(&[0,2,3][..]));
assert_eq!(it.next(), Some(&[8][..]));
assert_eq!(it.next(), None);
source

pub fn retain<Cb>(&mut self, cb: Cb)where Cb: FnMut(&mut T) -> bool,

Remove any items that don’t meet a predicate

use stack_dst::Fifo;
use core::any::Any;
use core::fmt::Debug;
trait DebugAny: 'static + Any + Debug { fn as_any(&self) -> &dyn Any; }
impl<T: Debug + Any + 'static> DebugAny for T { fn as_any(&self) -> &dyn Any { self } }
let mut list = {
    let mut list: Fifo<dyn DebugAny, ::stack_dst::buffers::Ptr8> = Fifo::new();
    list.push_back_stable(1234, |v| v);
    list.push_back_stable(234.5f32, |v| v);
    list.push_back_stable(5678, |v| v);
    list.push_back_stable(0.5f32, |v| v);
    list
    };
list.retain(|v| (*v).as_any().downcast_ref::<f32>().is_some());
let mut it = list.iter().map(|v| format!("{:?}", v));
assert_eq!(it.next(), Some("234.5".to_owned()));
assert_eq!(it.next(), Some("0.5".to_owned()));
assert_eq!(it.next(), None);
source§

impl<D: DataBuf> Fifo<str, D>

source

pub fn push_back_str(&mut self, v: &str) -> Result<(), ()>

Push the contents of a string slice as an item onto the stack

source§

impl<D: DataBuf, T: Clone> Fifo<[T], D>where (T, D::Inner): AlignmentValid,

source

pub fn push_cloned(&mut self, v: &[T]) -> Result<(), ()>

Pushes a set of items (cloning out of the input slice)

let mut queue = Fifo::<[String], ::stack_dst::buffers::Ptr8>::new();
queue.push_cloned(&["1".to_owned()]);
source

pub fn push_copied(&mut self, v: &[T]) -> Result<(), ()>where T: Copy,

Pushes a set of items (copying out of the input slice)

let mut queue = Fifo::<[usize], ::stack_dst::buffers::Ptr8>::new();
queue.push_copied(&[1]);
source§

impl<D: DataBuf, T> Fifo<[T], D>where (T, D::Inner): AlignmentValid,

source

pub fn push_from_iter( &mut self, iter: impl ExactSizeIterator<Item = T> ) -> Result<(), ()>

Push an item, populated from an exact-sized iterator

 
let mut stack = Fifo::<[u8], ::stack_dst::buffers::Ptr8>::new();
stack.push_from_iter(0..10);
assert_eq!(stack.front().unwrap(), &[0,1,2,3,4,5,6,7,8,9]);

Trait Implementations§

source§

impl<D: DataBuf, T> Debug for Fifo<T, D>where T: Debug + ?Sized,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: ?Sized, D: DataBuf + Default> Default for Fifo<T, D>

source§

fn default() -> Self

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

impl<T: ?Sized, D: DataBuf> Drop for Fifo<T, D>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T: ?Sized, D> RefUnwindSafe for Fifo<T, D>where D: RefUnwindSafe, T: RefUnwindSafe,

§

impl<T, D> !Send for Fifo<T, D>

§

impl<T, D> !Sync for Fifo<T, D>

§

impl<T: ?Sized, D> Unpin for Fifo<T, D>where D: Unpin,

§

impl<T: ?Sized, D> UnwindSafe for Fifo<T, D>where D: UnwindSafe, T: RefUnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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.