musli_zerocopy/stack/
mod.rs

1pub(crate) use self::array_stack::ArrayStack;
2mod array_stack;
3
4#[cfg(feature = "alloc")]
5use alloc::vec::Vec;
6
7/// Trait used to define a stack.
8pub(crate) trait Stack<T> {
9    const CAPACITY: usize;
10
11    fn new() -> Self;
12
13    fn try_push(&mut self, value: T) -> bool;
14
15    fn pop(&mut self) -> Option<T>;
16}
17
18#[cfg(feature = "alloc")]
19impl<T> Stack<T> for Vec<T> {
20    const CAPACITY: usize = usize::MAX;
21
22    #[inline]
23    fn new() -> Self {
24        Vec::new()
25    }
26
27    #[inline]
28    fn try_push(&mut self, value: T) -> bool {
29        Vec::push(self, value);
30        true
31    }
32
33    #[inline]
34    fn pop(&mut self) -> Option<T> {
35        Vec::pop(self)
36    }
37}