[][src]Trait unchecked_unwrap::UncheckedExpect

pub trait UncheckedExpect<T> {
    unsafe fn unchecked_expect(self, msg: &str) -> T;
}

Trait for unchecked_expect.

Required methods

unsafe fn unchecked_expect(self, msg: &str) -> T

Unwraps an Option or Result, yielding the content of a Some or Ok. This is the unchecked alternative to Option::expect and Result::expect.

Panics

Only panics if debug_assertions and the feature debug_checks is enabled.

Panics if the value is a None or Err, with a custom panic message provided by msg and if Result with the content of the Err.

Safety

Callers of this function are responsible that Option or Result carries a Some or Ok.

Failing that, the returned value may reference invalid memory or cause undefined behaviour.

Examples


let x = Some("value");
assert_eq!(unsafe { x.unchecked_expect("the world is ending") }, "value");

let x: Result<u32, &str> = Ok(2);
assert_eq!(unsafe { x.unchecked_expect("the sky is falling down") }, 2);
Loading content...

Implementations on Foreign Types

impl<T> UncheckedExpect<T> for Option<T>[src]

unsafe fn unchecked_expect(self, msg: &str) -> T[src]

Unwraps an Option, yielding the content of a Some. This is the unchecked alternative to expect.

impl<T, E: Debug> UncheckedExpect<T> for Result<T, E>[src]

unsafe fn unchecked_expect(self, msg: &str) -> T[src]

Unwraps a Result, yielding the content of an Ok. This is the unchecked alternative to expect.

Loading content...

Implementors

Loading content...