devela/data/collections/traits/
stacks.rsuse crate::{DataCollection, NotEnoughElements, NotEnoughSpace};
pub trait DataStack: DataCollection {
fn stack_pop(&mut self) -> Result<<Self as DataCollection>::Element, NotEnoughElements>;
fn stack_push(
&mut self,
element: <Self as DataCollection>::Element,
) -> Result<(), NotEnoughSpace>;
}
pub trait DataDesta: DataStack {
fn stack_pop_front(&mut self) -> Result<<Self as DataCollection>::Element, NotEnoughElements>;
fn stack_push_front(
&mut self,
element: <Self as DataCollection>::Element,
) -> Result<(), NotEnoughSpace>;
fn stack_pop_back(&mut self) -> Result<<Self as DataCollection>::Element, NotEnoughElements> {
self.stack_pop()
}
fn stack_push_back(
&mut self,
element: <Self as DataCollection>::Element,
) -> Result<(), NotEnoughSpace> {
self.stack_push(element)
}
}
#[rustfmt::skip]
#[cfg(feature = "alloc")]
impl<T> DataStack for crate::VecDeque<T> {
fn stack_pop(&mut self) -> Result<<Self as DataCollection>::Element, NotEnoughElements> {
self.pop_back().ok_or(NotEnoughElements(Some(1)))
}
fn stack_push(&mut self, element: <Self as DataCollection>::Element) -> Result<(), NotEnoughSpace> {
self.push_back(element); Ok(())
}
}
#[rustfmt::skip]
#[cfg(feature = "alloc")]
impl<T> DataDesta for crate::VecDeque<T> {
fn stack_pop_front(&mut self) -> Result<<Self as DataCollection>::Element, NotEnoughElements> {
self.pop_front().ok_or(NotEnoughElements(Some(1)))
}
fn stack_push_front(&mut self, element: <Self as DataCollection>::Element) -> Result<(), NotEnoughSpace> {
self.push_front(element); Ok(())
}
}