feat(interface-types) Stack supports Default.

This commit is contained in:
Ivan Enderlin 2019-09-20 11:55:19 +02:00
parent 9d4c983206
commit 39a817817b

View File

@ -8,18 +8,29 @@ pub trait Stackable {
fn pop(&mut self, n: usize) -> Option<Vec<Self::Item>>; fn pop(&mut self, n: usize) -> Option<Vec<Self::Item>>;
} }
#[derive(Debug)] #[derive(Debug, Default)]
pub struct Stack<T> { pub struct Stack<T>
where
T: Default,
{
inner: Vec<T>, inner: Vec<T>,
} }
impl<T> Stack<T> { impl<T> Stack<T>
where
T: Default,
{
pub fn new() -> Self { pub fn new() -> Self {
Self { inner: Vec::new() } Self {
..Default::default()
}
} }
} }
impl<T> Stackable for Stack<T> { impl<T> Stackable for Stack<T>
where
T: Default,
{
type Item = T; type Item = T;
fn is_empty(&self) -> bool { fn is_empty(&self) -> bool {