Type Alias DstQueueUsize

Source
pub type DstQueueUsize<DST, const CAP: usize> = DstQueue<DST, DstArray<usize, CAP>>;
Available on crate feature unsafe_layout only.
Expand description

📦 A statically allocated FIFO queue of DSTs with pointer alignment.

§Examples

let mut queue = DstQueueUsize::<[u8], 16>::new();
queue.push_copied(&[1]);

Aliased Type§

struct DstQueueUsize<DST, const CAP: usize> { /* private fields */ }

Implementations

Source§

impl<BUF: DstBuf, DST> DstQueue<[DST], BUF>
where (DST, BUF::Inner): MemAligned,

Source

pub fn push_cloned(&mut self, slice: &[DST]) -> Result<(), ()>
where DST: Clone,

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

§Examples
let mut queue = DstQueue::<[String], DstArray<usize, 8>>::new();
queue.push_cloned(&["1".to_owned()]);
Source

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

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

§Examples
let mut queue = DstQueue::<[usize], DstArray<usize, 8>>::new();
queue.push_copied(&[1]);
Source

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

Pushes an item, populated from an exact-sized iterator.

§Examples
let mut stack = DstQueue::<[u8], DstArray<usize, 8>>::new();
stack.push_from_iter(0..10);
assert_eq!(stack.front().unwrap(), &[0,1,2,3,4,5,6,7,8,9]);
Source§

impl<DST: ?Sized, BUF: DstBuf> DstQueue<DST, BUF>

Source

pub fn new() -> Self
where BUF: Default,

Constructs a new (empty) queue.

Source

pub fn with_buffer(data: BUF) -> Self

Constructs a new (empty) queue using the given buffer.

Source

pub fn push_back<VAL, F>(&mut self, value: VAL, f: F) -> Result<(), VAL>
where F: FnOnce(&VAL) -> &DST, (VAL, BUF::Inner): MemAligned,

Pushes a value to the end of the queue.

Source

pub fn compact(&mut self)

Compacts the queue (moving the read position to zero).

Source

pub const fn empty(&self) -> bool

Returns true if the queue is empty.

Source

pub fn pop_front(&mut self) -> Option<DstQueuePopHandle<'_, DST, BUF>>

Removes an item from the front of the queue.

Source

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

Returns an exclusive reference to the front element.

Source

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

Returns a shared reference to the front element.

Source

pub const fn iter(&self) -> DstQueueIter<'_, DST, BUF>

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

§Examples
let mut list = DstQueue::<str, DstArray<usize, 8>>::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) -> DstQueueIterMut<'_, DST, BUF>

Returns a mutable iterator.

§Examples
let mut list = DstQueue::<[u8], DstArray<usize, 8>>::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 DST) -> bool,

Removes any items that don’t meet a predicate.

§Examples
trait DebugAny: 'static + Any + Debug { fn as_any(&self) -> &dyn Any; }
impl<DST: Debug + Any + 'static> DebugAny for DST { fn as_any(&self) -> &dyn Any { self } }
let mut list = {
    let mut list: DstQueue<dyn DebugAny, DstArray<usize, 8>> = DstQueue::new();
    list.push_back(1234, |v| v);
    list.push_back(234.5f32, |v| v);
    list.push_back(5678, |v| v);
    list.push_back(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<BUF: DstBuf> DstQueue<str, BUF>

Source

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

Pushes the contents of a string slice as an item onto the stack.

Trait Implementations

Source§

impl<BUF: DstBuf, DST: ?Sized + Debug> Debug for DstQueue<DST, BUF>

Source§

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

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

impl<DST: ?Sized, BUF: DstBuf + Default> Default for DstQueue<DST, BUF>

Source§

fn default() -> Self

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

impl<DST: ?Sized, BUF: DstBuf> Drop for DstQueue<DST, BUF>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more