In Rust, Option<Box<T>> uses the same memory layout as Box<T>, e.g. Option takes no space. The Rust compiler knows that pointers cannot be null, so uses the null bit pattern to encode None.

Jan 5, 2023 · 9:43 AM UTC

4
28
509
51,496
Sort replies: Relevant Recent Liked
Replying to @timClicks
I always wondered if this was a "hardcoded" feature or if you can apply it to your own types? For example, defining in some way that your struct T has an unrepresentable state, so that Option<T> uses that state for None.
5
17
2,581
Replying to @timClicks
Two views of null diverged in a wood, and I Took the one with distinct types, and That has made all the difference.
5
692
Replying to @timClicks
@MonniauxD the source of all your problems
1,367