AssertSomeExt

Trait AssertSomeExt 

Source
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§

Source

fn assert_some(self) -> Self

Asserts the Option is Some.

§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(|v| v * 2);
assert_eq!(x, Some(42));
use chain_assertions::prelude::*;

let x: Option<i32> = None;
let _ = x.assert_some().map(|v| v * 2);
//        ^-- panics here
Source

fn debug_assert_some(self) -> Self

Asserts the Option is Some only in debug builds.

§Panics

If it is None and debug_assertions are enabled, the method panics. If debug_assertions are disabled, the method is a no-op even if it is None.

§Examples
use chain_assertions::prelude::*;

let x: Option<i32> = Some(21);
let x = x.debug_assert_some().map(|v| v * 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.

Implementations on Foreign Types§

Source§

impl<T> AssertSomeExt for Option<T>

Source§

fn assert_some(self) -> Self

Source§

fn debug_assert_some(self) -> Self

Implementors§