use crate::{list::Array, mem::Storage};
#[cfg(feature = "alloc")]
use crate::mem::Boxed;
mod data;
mod impls;
mod methods;
pub use data::DataStack;
pub struct Stack<T, S: Storage, const CAP: usize> {
pub(crate) array: Array<T, S, CAP>,
pub(crate) len: usize,
}
pub type DirectStack<T, const CAP: usize> = Stack<T, (), CAP>;
#[cfg(feature = "alloc")]
#[cfg_attr(feature = "nightly", doc(cfg(feature = "alloc")))]
pub type BoxedStack<T, const CAP: usize> = Stack<T, Boxed, CAP>;
pub struct StackIter<'s, T, S: Storage, const CAP: usize> {
stack: &'s Stack<T, S, CAP>,
idx: usize,
}
impl<'s, T, S: Storage, const CAP: usize> Iterator for StackIter<'s, T, S, CAP> {
type Item = &'s T;
fn next(&mut self) -> Option<Self::Item> {
let item = if self.idx == self.stack.len() {
None
} else {
Some(&self.stack.array[self.idx])
};
self.idx += 1;
item
}
fn size_hint(&self) -> (usize, Option<usize>) {
(self.stack.len(), Some(self.stack.len()))
}
}
impl<'s, T, S: Storage, const CAP: usize> ExactSizeIterator for StackIter<'s, T, S, CAP> {}