#[derive(Debug)]
struct Node {
    value: i32,
    next: Option<Box<Node>>,
}

fn build_chain() -> Option<Box<Node>> {
    let mut p = None;
    for i in 0..3 {
        p = Some(Box::new(Node {
            value: i,
            next: p,
        }));
    }
    p
}

fn print_chain(mut p: &Option<Box<Node>>) {
    let mut values = vec![];
    while let Some(node) = p {
        values.push(node.value.to_string());
        p = &node.next;
    }
    println!("{}", values.join(" -> "))
}

fn main() {
    let p = build_chain();
    print_chain(&p);
}