Answers for "rust•armanazi•error•[E0072]: recursive type `List` has infinite size --> src/main.rs:3:1 | 3 | enum List { | ^^^^^^^^^ recursive type has infinite size"

0

rust•armanazi•error•[E0072]: recursive type `List` has infinite size --> src/main.rs:3:1 | 3 | enum List { | ^^^^^^^^^ recursive type has infinite size

//resolved:Definition of List that uses Box<T> in order to have a known size
enum List {
    Cons(i32, Box<List>),
    Nil,
}

use crate::List::{Cons, Nil};

fn main() {
    let list = Cons(1, Box::new(Cons(2, Box::new(Cons(3, Box::new(Nil))))));
}
Posted by: Guest on March-24-2022

Browse Popular Code Answers by Language