std-method

Option::flatten

Remove exactly one layer of optional nesting. Either kind of absence becomes None. Expected stdout (not executed): Some(7) Common mistake: Expecting flatten to preserve the distinction between Some(None) and None.

Formal Syntax & Structure

rust syntaxrust
Option<Option<T>>::flatten(self) -> Option<T>

Working Example

Example Snippetrust
fn main() {    let nested = Some(Some(7));    println!("{:?}", nested.flatten());}
Rust Reference