diff --git a/src/main.rs b/src/main.rs index e1cd2e7..54cb08b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,22 +1,23 @@ -fn main() { - -} +fn main() {} +#[derive(Debug)] pub struct List { - head: Link + head: Link, } -enum Link{ +#[derive(Debug)] +enum Link { Empty, More(Box), } +#[derive(Debug)] struct Node { elem: i32, next: Link, } -impl List{ +impl List { pub fn new() -> Self { Self { head: Link::Empty } } @@ -24,9 +25,10 @@ impl List{ pub fn push(&mut self, elem: i32) { let new_node = Node { elem: elem, - next: std::mem::replace(&mut self.head, Link::Empty) + next: std::mem::replace(&mut self.head, Link::Empty), }; + self.head = Link::More(Box::new(new_node)); } - } +