enum List {
    Node(i32, Box<List>),
    Tail,
}

use List::{Node, Tail};

impl List {
    fn new() -> List {
        Tail
    }

    fn prepend(self, elem: i32) -> List {
        Node(elem, Box::new(self))
    }
}

fn main() {
    let mut list = List::new();
    list = list.prepend(0);
    list = list.prepend(1); 
    list = list.prepend(2); 

    let mut l = &list;
    loop {
        match &*l {
            Node(value, next) => {
                println!("Node: {value}");
                l = &next;
            },
            Tail => {
                println!("Tail");
                break;
            },
        }
    }
}
