Expand description
A fixed-capacity stack that can contain dynamically-sized types
Uses an array of usize as a backing store for a First-In, Last-Out stack
of items that can unsize to T
.
Note: Each item in the stack takes at least one slot in the buffer (to store the metadata)
Implementations
sourceimpl<T: ?Sized, D: DataBuf> StackA<T, D>
impl<T: ?Sized, D: DataBuf> StackA<T, D>
sourcepub fn with_buffer(data: D) -> Self
pub fn with_buffer(data: D) -> Self
Construct a new (empty) stack using the provided buffer
sourcepub fn push<U: Unsize<T>>(&mut self, v: U) -> Result<(), U> where
(U, D::Inner): AlignmentValid,
pub fn push<U: Unsize<T>>(&mut self, v: U) -> Result<(), U> where
(U, D::Inner): AlignmentValid,
Push a value at the top of the stack
sourcepub fn push_stable<U, F: FnOnce(&U) -> &T>(
&mut self,
v: U,
f: F
) -> Result<(), U> where
(U, D::Inner): AlignmentValid,
pub fn push_stable<U, F: FnOnce(&U) -> &T>(
&mut self,
v: U,
f: F
) -> Result<(), U> where
(U, D::Inner): AlignmentValid,
Push a value at the top of the stack (without using Unsize
)
sourcepub fn top_mut(&mut self) -> Option<&mut T>
pub fn top_mut(&mut self) -> Option<&mut T>
Returns a pointer to the top item on the stack (unique/mutable)
sourcepub fn iter(&self) -> Iter<'_, T, D>ⓘNotable traits for Iter<'a, T, D>impl<'a, T: 'a + ?Sized, D: 'a + DataBuf> Iterator for Iter<'a, T, D> type Item = &'a T;
pub fn iter(&self) -> Iter<'_, T, D>ⓘNotable traits for Iter<'a, T, D>impl<'a, T: 'a + ?Sized, D: 'a + DataBuf> Iterator for Iter<'a, T, D> type Item = &'a T;
Obtain an immutable iterator (yields references to items, in the order they would be popped)
let mut list = ::stack_dst::StackA::<str, [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) -> IterMut<'_, T, D>ⓘNotable traits for IterMut<'a, T, D>impl<'a, T: 'a + ?Sized, D: 'a + DataBuf> Iterator for IterMut<'a, T, D> type Item = &'a mut T;
pub fn iter_mut(&mut self) -> IterMut<'_, T, D>ⓘNotable traits for IterMut<'a, T, D>impl<'a, T: 'a + ?Sized, D: 'a + DataBuf> Iterator for IterMut<'a, T, D> type Item = &'a mut T;
Obtain unique/mutable iterator
let mut list = ::stack_dst::StackA::<[u8], [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);
Trait Implementations
Auto Trait Implementations
impl<T: ?Sized, D> RefUnwindSafe for StackA<T, D> where
D: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, D> !Send for StackA<T, D>
impl<T, D> !Sync for StackA<T, D>
impl<T: ?Sized, D> Unpin for StackA<T, D> where
D: Unpin,
impl<T: ?Sized, D> UnwindSafe for StackA<T, D> where
D: UnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more