1use core::fmt::Debug;
2
3mod r#const;
4pub use r#const::ConstStack;
5
6#[derive(Clone, Copy, Debug)]
8pub enum State {
9 Object,
11 Array,
13 Unknown,
15}
16
17pub trait Stack: Debug {
19 type Error: Sized + Copy + Debug;
21
22 fn empty() -> Self;
24
25 fn depth(&self) -> usize;
27
28 fn peek(&self) -> Option<State>;
30
31 fn pop(&mut self) -> Option<State>;
33
34 fn push(&mut self, item: State) -> Result<(), Self::Error>;
36}
37
38#[cfg(feature = "alloc")]
39use alloc::vec::Vec;
40#[cfg(feature = "alloc")]
46impl Stack for Vec<State> {
47 type Error = core::convert::Infallible;
48
49 #[inline(always)]
50 fn empty() -> Self {
51 Vec::with_capacity(1)
52 }
53
54 #[inline(always)]
55 fn depth(&self) -> usize {
56 self.len()
57 }
58
59 #[inline(always)]
60 fn peek(&self) -> Option<State> {
61 self.last().copied()
62 }
63
64 #[inline(always)]
65 fn pop(&mut self) -> Option<State> {
66 Vec::<State>::pop(self)
67 }
68
69 #[inline(always)]
70 fn push(&mut self, item: State) -> Result<(), Self::Error> {
71 Vec::<State>::push(self, item);
72 Ok(())
73 }
74}