use core::fmt::Debug;
mod r#const;
pub use r#const::ConstStack;
#[derive(Clone, Copy, Debug)]
pub enum State {
Object,
Array,
Unknown,
}
pub trait Stack: Debug {
type Error: Sized + Copy + Debug;
fn empty() -> Self;
fn depth(&self) -> usize;
fn peek(&self) -> Option<State>;
fn pop(&mut self) -> Option<State>;
fn push(&mut self, item: State) -> Result<(), Self::Error>;
}
#[cfg(feature = "alloc")]
use alloc::vec::Vec;
#[cfg(feature = "alloc")]
impl Stack for Vec<State> {
type Error = core::convert::Infallible;
#[inline(always)]
fn empty() -> Self {
Vec::with_capacity(1)
}
#[inline(always)]
fn depth(&self) -> usize {
self.len()
}
#[inline(always)]
fn peek(&self) -> Option<State> {
self.last().copied()
}
#[inline(always)]
fn pop(&mut self) -> Option<State> {
Vec::<State>::pop(self)
}
#[inline(always)]
fn push(&mut self, item: State) -> Result<(), Self::Error> {
Vec::<State>::push(self, item);
Ok(())
}
}