Answer the question
In order to leave comments, you need to log in
What is the purpose of Empty and Elem in a primitive data structure?
I have a simple list:
pub enum List {
Empty,
Elem(i32, Box<List>),
}
Answer the question
In order to leave comments, you need to log in
> Why should I write Empty here if it compiles without it?
The enumeration itself without Elem compiles, but constructing a real list without a terminating empty node will not work, because it would have to be infinite.
> What is Elem?
This is one of the variants of the declared List enumeration, which contains two unnamed fields of clear types.
> I did not declare it additionally and did not find it mentioned in the documentation, but it works.
This is just the simplest enum syntax, which is described in any Rust textbook, for example, in the Rust Book: https://doc.rust-lang.org/book/ch06-01-defining-an...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question