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,
impl<BUF: DstBuf, DST: Clone> DstStack<[DST], BUF>where
(DST, BUF::Inner): MemAligned,
Source§impl<BUF: DstBuf, DST> DstStack<[DST], BUF>where
(DST, BUF::Inner): MemAligned,
impl<BUF: DstBuf, DST> DstStack<[DST], BUF>where
(DST, BUF::Inner): MemAligned,
Sourcepub fn push_from_iter(
&mut self,
iter: impl ExactSizeIterator<Item = DST>,
) -> Result<(), ()> ⓘ
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>
impl<DST: ?Sized, BUF: DstBuf> DstStack<DST, BUF>
Sourcepub const fn new_const() -> Selfwhere
BUF: ConstDefault,
pub const fn new_const() -> Selfwhere
BUF: ConstDefault,
Constructs a new (empty) stack, in compile-time.
Sourcepub const fn with_buffer(buffer: BUF) -> Self
pub const fn with_buffer(buffer: BUF) -> Self
Constructs a new (empty) stack using the given buffer
.
Sourcepub fn push<VAL, F: FnOnce(&VAL) -> &DST>(
&mut self,
v: VAL,
f: F,
) -> Result<(), VAL> ⓘwhere
(VAL, BUF::Inner): MemAligned,
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);
Sourcepub fn top_mut(&mut self) -> Option<&mut DST> ⓘ
pub fn top_mut(&mut self) -> Option<&mut DST> ⓘ
Returns an exclusive reference to the top item on the stack.
Sourcepub const fn iter(&self) -> DstStackIter<'_, DST, BUF> ⓘ
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);
Sourcepub fn iter_mut(&mut self) -> DstStackIterMut<'_, DST, BUF> ⓘ
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);