#[derive(Clone)]
pub struct Stack<T> {
stack: Vec<T>,
}
impl<T> Stack<T> {
pub fn new(capacity: usize) -> Stack<T> {
Stack {
stack: Vec::with_capacity(capacity),
}
}
#[inline]
pub fn push(&mut self, value: T) {
self.stack.push(value);
}
#[inline]
pub fn pop(&mut self) -> Option<T> {
self.stack.pop()
}
#[inline]
pub fn len(&self) -> usize {
self.stack.len()
}
#[inline]
pub fn is_empty(&self) -> bool {
self.stack.is_empty()
}
#[inline]
pub fn peek(&self) -> &T {
self.stack.last().unwrap()
}
#[inline]
pub fn contains(&self, value: &T) -> bool
where
T: PartialEq,
{
self.stack.contains(value)
}
}
impl Stack<(u16, bool)> {
pub fn iter(&self) -> std::slice::Iter<(u16, bool)> {
self.stack.iter()
}
}
impl IntoIterator for Stack<(u16, bool)> {
type Item = (u16, bool);
type IntoIter = std::vec::IntoIter<(u16, bool)>;
fn into_iter(self) -> Self::IntoIter {
self.stack.into_iter()
}
}