Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardRustniche optimizationSingle-choice MCQ

Two niche carriers behave very differently when wrapped in nested `Option`s. Given the sizes below, what general rule about how rustc allocates niches explains why the `NonZeroU32` case grows but the `bool` case does not?

use std::mem::size_of; use std::num::NonZeroU32; // size_of::<Option<NonZeroU32>>() == 4 // size_of::<Option<Option<NonZeroU32>>>() == 8 // size_of::<Option<bool>>() == 1 // size_of::<Option<Option<Option<bool>>>>() == 1