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")]
41impl Stack for Vec<State> {
42 type Error = core::convert::Infallible;
43
44 #[inline(always)]
45 fn empty() -> Self {
46 Vec::with_capacity(1)
47 }
48
49 #[inline(always)]
50 fn depth(&self) -> usize {
51 self.len()
52 }
53
54 #[inline(always)]
55 fn peek(&self) -> Option<State> {
56 self.last().copied()
57 }
58
59 #[inline(always)]
60 fn pop(&mut self) -> Option<State> {
61 Vec::<State>::pop(self)
62 }
63
64 #[inline(always)]
65 fn push(&mut self, item: State) -> Result<(), Self::Error> {
66 Vec::<State>::push(self, item);
67 Ok(())
68 }
69}