Trait TryUnwrapOption

Source
pub trait TryUnwrapOption {
    type T;

    // Required method
    fn try_unwrap(self) -> Option<Self::T>;
}
Expand description

Trait for implementing try_unwrap() on the generic Option<T> type.

Required Associated Types§

Source

type T

Required Methods§

Source

fn try_unwrap(self) -> Option<Self::T>

Implementations on Foreign Types§

Source§

impl<T> TryUnwrapOption for Option<T>

Source§

fn try_unwrap(self) -> Option<T>

Unwraps and returns the contained value if it is a Some. Otherwise, it returns a None.

let some: Option<i32> = Some(4);
assert_eq!(some.try_unwrap(), Some(4));
let none: Option<i32> = None;
assert_eq!(none.try_unwrap(), None);
Source§

type T = T

Implementors§