[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 Introduction - Learning Rust With Entirely Too Many Linked 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 std - Rust

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.