Trait rustbasic::Errexit

source ·
pub trait Errexit<T> {
    // Required method
    fn errexit(self) -> T;
}

Required Methods§

source

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!

Implementations on Foreign Types§

source§

impl<T> Errexit<T> for Option<T>

source§

fn errexit(self) -> T

source§

impl<T, E> Errexit<T> for Result<T, E>where E: Debug,

source§

fn errexit(self) -> Twhere E: Debug,

Implementors§