std/option¶
module option for Option<T>
The ways out of an Option<T>, in the prelude, each stating what
absence gives. There is no unwrap. map and filter over an option
are the core's steps applied to the present value. See
Option: a value that may be missing.
is_some— Whetherselfholds a value:some(3) | is_someistrue.is_none— Whetherselfisnone:[1, 2][5] | is_noneistrue.unwrap_or— The value ofselfwhen present, anddefaultotherwise:[1, 2][5] | unwrap_or(0)is0.unwrap_or_else— The value ofselfwhen present, and whatdefaultreturns otherwise;defaultis called only whenselfisnone:[1, 2][5] | unwrap_or_else(() => 7)is7.and_then—byapplied to the value ofselfwhen present, its ownnonekept, andnoneotherwise:[4][0] | and_then(x => [10][x])isnone.or_else—selfwhen present, and the optiondefaultreturns otherwise:[1][5] | or_else(() => [9][0])is9.alternative—selfwhen present, andotherotherwise:[1][5] | alternative([9][0])is9.