Type Alias DstStackUsize

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

📦 A statically allocated LIFO stack of DSTs with pointer alignment.

§Examples

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

Aliased Type§

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

Implementations

Source§

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

Source

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

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

§Examples
let mut stack = DstStack::<[u8], DstArray<u64, 8>>::new();
stack.push_cloned(&[1, 2, 3]);
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 stack = DstStack::<[u8], DstArray<u64, 8>>::new();
stack.push_copied(&[1, 2, 3]);
Source§

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

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 = DstStack::<[u8], DstArray<usize, 8>>::new();
stack.push_from_iter(0..10);
assert_eq!(stack.top().unwrap(), &[0,1,2,3,4,5,6,7,8,9]);
Source§

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

Source

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

Constructs a new (empty) stack.

Source

pub const fn new_const() -> Self
where BUF: ConstDefault,

Constructs a new (empty) stack, in compile-time.

Source

pub const fn with_buffer(buffer: BUF) -> Self

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

Source

pub const fn is_empty(&self) -> bool

Returns true if the stack is empty.

Source

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

Pushes a value at the top of the stack.

let mut stack = DstStack::<[u8], DstArray<u64, 8>>::new();
stack.push([1, 2,3], |v| v);
Source

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

Returns a shared reference to the top item on the stack.

Source

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

Returns an exclusive reference to the top item on the stack.

Source

pub fn pop(&mut self)

Pops the top item off the stack.

Source

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

Returns an immutable iterator (yields references to items, in the order they would be popped).

§Examples
let mut list = DstStack::<str, DstArray<usize, 8>>::new();
list.push_str("Hello");
list.push_str("world");
let mut it = list.iter();
assert_eq!(it.next(), Some("world"));
assert_eq!(it.next(), Some("Hello"));
assert_eq!(it.next(), None);
Source

pub fn iter_mut(&mut self) -> DstStackIterMut<'_, DST, BUF>

Returns a mutable iterator.

§Examples
let mut list = DstStack::<[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(&[8][..]));
assert_eq!(it.next(), Some(&[0,2,3][..]));
assert_eq!(it.next(), None);
Source§

impl<BUF: DstBuf> DstStack<str, BUF>

Source

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

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

§Examples
let mut stack = DstStack::<str, DstArray<u8, 32>>::new();
stack.push_str("Hello!");

Trait Implementations

Source§

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

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 DstStack<DST, BUF>

Source§

fn default() -> Self

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

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

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more