pub trait AssertSomeExt {
// Required methods
fn assert_some(self) -> Self;
fn debug_assert_some(self) -> Self;
}Expand description
An extension trait to add the assertion_some methods.
Required Methods§
Sourcefn assert_some(self) -> Self
fn assert_some(self) -> Self
§Panics
If it is None, the method panics.
§Examples
use chain_assertions::prelude::*;
let x: Option<i32> = Some(21);
let x = x.assert_some().map(|x| x * 2);
assert_eq!(x, Some(42));ⓘ
use chain_assertions::prelude::*;
let x: Option<i32> = None;
let _ = x.assert_some().map(|x| x * 2);
// ^-- panics hereSourcefn debug_assert_some(self) -> Self
fn debug_assert_some(self) -> Self
Asserts the Option is Some only in debug builds.
§Panics
The method panics if all following conditions are satisfied:
- It is
None debug_assertionsis enabledpassthroughfeature is disabled
Otherwise, the method returns self as is.
§Examples
use chain_assertions::prelude::*;
let x: Option<i32> = Some(21);
let x = x.debug_assert_some().map(|x| x * 2);
assert_eq!(x, Some(42));Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.