[Question]: E0072 - Recursing enums

Hello.
I am having some issues involving enums that could recurse.

Node::BinaryOpNode will recurse with two other Nodes which could recurse farther or it could stop at Int, Float, or String. Is there a way to make it allow/work around this?

pub enum Node {
    IntNode {
        token: tokens::Token,
        value: i32,
        start: lexer::LexerPosition, end: lexer::LexerPosition
    },
    FloatNode {
        token: tokens::Token,
        value: f32,
        start: lexer::LexerPosition, end: lexer::LexerPosition
    },
    StringNode {
        token: tokens::Token,
        value: String,
        start: lexer::LexerPosition, end: lexer::LexerPosition
    },

    BinaryOpNode {
        left   : Node,
        optoken: tokens::Token,
        right  : Node,
        start: lexer::LexerPosition, end: lexer::LexerPosition
    }
}

Change left and right to Box<Node>.

Also, read https://rust-unofficial.github.io/too-many-lists/, which describes a lot about data structures in Rust.

1 Like

Box<Node> is the way to go. If you want to know more, (re)read the chapter in the book.

It worked. Thank you!
Am I the only person who can't access docs.rust-lang.org?

It is https://doc.rust-lang.org/ with the s.

Edit: both work apparently. The docs are at https://doc.rust-lang.org/stable/std/