std/result¶
module result for Result<T, E>
The ways out of a Result<T, E>, in the prelude, each stating what a
failure gives. A result is ok(v) or err(e). There is no unwrap.
map over a result is the core's step applied to the value of a success:
ok(3) | map(n => n + 1) is ok(4).
is_ok— Whetherselfis a success:ok(4) | is_okistrue.is_err— Whetherselfis a failure:err("x") | is_erristrue.ok— The value ofselfwhen a success, andnonewhen a failure:err("x") | okisnone.err— The error ofselfwhen a failure, andnonewhen a success:ok(4) | errisnone.unwrap_or— The value ofselfwhen a success, anddefaultwhen a failure:err("x") | unwrap_or(0)is0.unwrap_or_else— The value ofselfwhen a success, anddefaultapplied to the error when a failure:err("ab") | unwrap_or_else(e => e.size())is2.map_err— A failure withbyapplied to its error; a success is kept as it is:err("x") | map_err(e => e.upper())iserr("X").and_then—byapplied to the value of a success, its own failure kept; a failure is kept as it is:ok(4) | and_then(n => ok(n * 2))isok(8).or_else—byapplied to the error of a failure, giving another result; a success is kept as it is:err("x") | or_else(e => ok(e.size()))isok(1).