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§
Sourcefn try_unwrap(self, context: &'static str) -> Result<T, UnwrapError>
fn try_unwrap(self, context: &'static str) -> Result<T, UnwrapError>
Try to unwrap a value, returning a Result
Provided Methods§
Sourcefn try_unwrap_at(
self,
context: &'static str,
location: &'static str,
) -> Result<T, UnwrapError>where
Self: Sized,
fn try_unwrap_at(
self,
context: &'static str,
location: &'static str,
) -> Result<T, UnwrapError>where
Self: Sized,
Try to unwrap with location information
Sourcefn unwrap_or_default_safe(self, default: T, context: &'static str) -> Twhere
Self: Sized,
fn unwrap_or_default_safe(self, default: T, context: &'static str) -> Twhere
Self: Sized,
Unwrap or return a default value
Sourcefn unwrap_or_else_safe<F>(self, default_fn: F, context: &'static str) -> T
fn unwrap_or_else_safe<F>(self, default_fn: F, context: &'static str) -> T
Unwrap or compute a default value
Sourcefn try_unwrap_safe(self, context: &'static str) -> Result<T, MemScopeError>where
Self: Sized,
👎Deprecated: Use try_unwrap() instead
fn try_unwrap_safe(self, context: &'static str) -> Result<T, MemScopeError>where
Self: Sized,
Backwards compatibility method (deprecated)
Sourcefn unwrap_safe(self, context: &'static str) -> Twhere
Self: Sized,
👎Deprecated: Use try_unwrap() instead
fn unwrap_safe(self, context: &'static str) -> Twhere
Self: Sized,
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.
Sourcefn unwrap_safe_at(self, context: &'static str, location: &'static str) -> Twhere
Self: Sized,
👎Deprecated: Use try_unwrap_at() instead
fn unwrap_safe_at(self, context: &'static str, location: &'static str) -> Twhere
Self: Sized,
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>
impl<T> UnwrapSafe<T> for Option<T>
fn try_unwrap(self, context: &'static str) -> Result<T, UnwrapError>
fn unwrap_or_else_safe<F>(self, default_fn: F, context: &'static str) -> Twhere
F: FnOnce() -> T,
Source§fn try_unwrap_safe(self, context: &'static str) -> Result<T, MemScopeError>
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>
impl<T, E: StdError + Send + Sync + 'static> UnwrapSafe<T> for Result<T, E>
fn try_unwrap(self, context: &'static str) -> Result<T, UnwrapError>
fn try_unwrap_at( self, context: &'static str, location: &'static str, ) -> Result<T, UnwrapError>
fn unwrap_or_default_safe(self, default: T, context: &str) -> T
fn unwrap_or_else_safe<F>(self, default_fn: F, context: &str) -> Twhere
F: FnOnce() -> T,
Source§fn try_unwrap_safe(self, context: &str) -> Result<T, MemScopeError>
fn try_unwrap_safe(self, context: &str) -> Result<T, MemScopeError>
👎Deprecated: Use try_unwrap() instead