diff --git a/src/main.rs b/src/main.rs index ebfafc1..0e7feed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,28 +9,28 @@ fn main() { } #[derive(Debug)] -pub struct List { - head: Link, +pub struct List { + head: Link, } #[derive(Debug)] -enum Link { +enum Link { Empty, - More(Box), + More(Box>), } #[derive(Debug)] -struct Node { - elem: i32, - next: Link, +struct Node { + elem: T, + next: Link, } -impl List { +impl List { pub fn new() -> Self { Self { head: Link::Empty } } - pub fn push(&mut self, elem: i32) { + pub fn push(&mut self, elem: T) { let new_node = Node { elem: elem, next: std::mem::replace(&mut self.head, Link::Empty), @@ -38,7 +38,7 @@ impl List { self.head = Link::More(Box::new(new_node)); } - pub fn pop(&mut self) -> Option { + pub fn pop(&mut self) -> Option { match std::mem::replace(&mut self.head, Link::Empty) { Link::Empty => None, Link::More(node) => {