I am making a board game and have the following enum.
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Stone {
Red,
Green,
Blue,
Yellow,
}
I wanted to see what the size of Option<Stone>
and Stone
were, so I ran the following code and found that both had a size of 1 on Rust 1.80.1.
fn main() {
// Both print 1.
println!("{}", std::mem::size_of::<Option<Stone>>());
println!("{}", std::mem::size_of::<Stone>());
}
I know that Option<NonZero<T>>
and T
have the same size, but I don't know what happens when NonZero
is not used in the definition, as in the Stone
example above.
Why are Option<Stone>
and Stone
the same size?