Ad
  • Custom User Avatar

    Just copy the struct and create the simple methods for creating the children nodes.

    Something like this:

    struct Node {
        value: u32,
        left: Option<Box<Node>>,
        right: Option<Box<Node>>,
    }
    
    impl Node {
        fn new(value: u32) -> Self {
            Node {
                value,
                left: None,
                right: None,
            }
        }
    
        fn left(mut self, node: Node) -> Node {
            self.left = Some(Box::new(node));
            self
        }
    
        fn right(mut self, node: Node) -> Node {
            self.right = Some(Box::new(node));
    
            self
        }
    }
    
  • Custom User Avatar

    You must return the result, not print it.