If I define the following enums, Nil does not increase the size of the enum:
use std::mem::size_of;
enum Foo {
Cons(~char)
}
enum Bar {
Cons(~char),
Nil
}
println!("{}", size_of::<Foo>());
println!("{}", size_of::<Bar>());
// -> 4
// -> 4
On the other hand:
enum Foo {
Cons(char)
}
enum Foo {
Cons(char),
Nil
}
Yields:
// -> 4
// -> 8
What is happening when I define an enum? How is memory being allocated for these structures?