module-concept

Option<NonZeroU8> layout

The zero representation is unavailable to NonZeroU8, so Option can use it for None. The documented layout guarantee applies to this combination; do not generalize it to all Option types. Expected stdout (not executed): 1 1 Common mistake: Assuming every Option has the same size as its inner type.

Formal Syntax & Structure

rust syntaxrust
std::mem::size_of::<Option<NonZeroU8>>()

Working Example

Example Snippetrust
fn main() {    use std::{mem::size_of, num::NonZeroU8};    println!("{} {}", size_of::<u8>(), size_of::<Option<NonZeroU8>>());}
Rust Reference