[][src]Trait unchecked_unwrap::UncheckedUnwrap

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

Required methods

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

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 cfg(debug_assertions) and feature="debug_checks" is enabled and the value is a None or 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

use unchecked_unwrap::UncheckedUnwrap;

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);

unsafe fn unchecked_unwrap(self) -> T[src]

Unwraps an Option or Result, yielding the content of a Some or Ok.

This is the unchecked alternative to Option::unwrap and Result::unwrap.

Panics

Only panics if cfg(debug_assertions) and feature="debug_checks" is enabled and the value is a None or 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

use unchecked_unwrap::UncheckedUnwrap;

let x = Some("air");
assert_eq!(unsafe { x.unchecked_unwrap() }, "air");

let x: Result<u32, &str> = Ok(2);
assert_eq!(unsafe { x.unchecked_unwrap() }, 2);
Loading content...

Implementations on Foreign Types

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

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

Loading content...

Implementors

Loading content...