UnwrapSafe

Trait UnwrapSafe 

Source
pub trait UnwrapSafe<T> {
    // Required method
    fn try_unwrap(self, context: &'static str) -> Result<T, UnwrapError>;

    // Provided methods
    fn try_unwrap_at(
        self,
        context: &'static str,
        location: &'static str,
    ) -> Result<T, UnwrapError>
       where Self: Sized { ... }
    fn unwrap_or_default_safe(self, default: T, context: &'static str) -> T
       where Self: Sized { ... }
    fn unwrap_or_else_safe<F>(self, default_fn: F, context: &'static str) -> T
       where Self: Sized,
             F: FnOnce() -> T { ... }
    fn try_unwrap_safe(self, context: &'static str) -> Result<T, MemScopeError>
       where Self: Sized { ... }
    fn unwrap_safe(self, context: &'static str) -> T
       where Self: Sized { ... }
    fn unwrap_safe_at(self, context: &'static str, location: &'static str) -> T
       where Self: Sized { ... }
}
Expand description

Extension trait for safe, panic-free unwrapping

Required Methods§

Source

fn try_unwrap(self, context: &'static str) -> Result<T, UnwrapError>

Try to unwrap a value, returning a Result

Provided Methods§

Source

fn try_unwrap_at( self, context: &'static str, location: &'static str, ) -> Result<T, UnwrapError>
where Self: Sized,

Try to unwrap with location information

Source

fn unwrap_or_default_safe(self, default: T, context: &'static str) -> T
where Self: Sized,

Unwrap or return a default value

Source

fn unwrap_or_else_safe<F>(self, default_fn: F, context: &'static str) -> T
where Self: Sized, F: FnOnce() -> T,

Unwrap or compute a default value

Source

fn try_unwrap_safe(self, context: &'static str) -> Result<T, MemScopeError>
where Self: Sized,

👎Deprecated: Use try_unwrap() instead

Backwards compatibility method (deprecated)

Source

fn unwrap_safe(self, context: &'static str) -> T
where Self: Sized,

👎Deprecated: Use try_unwrap() instead

Unwrap with context information (deprecated) Unwrap or abort the process

§Safety

This method will abort the process on error. Only use when the program cannot continue without this value.

Source

fn unwrap_safe_at(self, context: &'static str, location: &'static str) -> T
where Self: Sized,

👎Deprecated: Use try_unwrap_at() instead

Unwrap with context and location information (deprecated) Unwrap or abort the process with location information

§Safety

This method will abort the process on error. Only use when the program cannot continue without this value.

Implementations on Foreign Types§

Source§

impl<T> UnwrapSafe<T> for Option<T>

Source§

fn try_unwrap(self, context: &'static str) -> Result<T, UnwrapError>

Source§

fn unwrap_or_else_safe<F>(self, default_fn: F, context: &'static str) -> T
where F: FnOnce() -> T,

Source§

fn try_unwrap_safe(self, context: &'static str) -> Result<T, MemScopeError>

👎Deprecated: Use try_unwrap() instead
Source§

impl<T, E: StdError + Send + Sync + 'static> UnwrapSafe<T> for Result<T, E>

Source§

fn try_unwrap(self, context: &'static str) -> Result<T, UnwrapError>

Source§

fn try_unwrap_at( self, context: &'static str, location: &'static str, ) -> Result<T, UnwrapError>

Source§

fn unwrap_or_default_safe(self, default: T, context: &str) -> T

Source§

fn unwrap_or_else_safe<F>(self, default_fn: F, context: &str) -> T
where F: FnOnce() -> T,

Source§

fn try_unwrap_safe(self, context: &str) -> Result<T, MemScopeError>

👎Deprecated: Use try_unwrap() instead

Implementors§