pub trait Errexit<T> {
// Required method
fn errexit(self) -> T;
}
Required Methods§
sourcefn errexit(self) -> T
fn errexit(self) -> T
This function implements unwrap()
as errexit()
.
errexit()
is used in Option
and Result
types, and returns the internal value if the corresponding value is Some
or Ok
.
If it is None
or Err
, it panics by default.
Therefore, errexit()
should be used only when it is certain that a value exists, allowing you to safely extract that value and proceed to the next step.
Examples
ⓘ
use rustbasic::*;
let _a: Option<usize> = Some(123);
let _b: Option<usize> = None;
let _c = get_ok();
let _d = get_err();
println!("{:?}", _a.errexit());
// println!("{:?}", _b.errexit()); // It panics!
println!("{:?}", _c.errexit());
// println!("{:?}", _d.errexit()); // It panics!