AssertNoneExt

Trait AssertNoneExt 

Source
pub trait AssertNoneExt {
    // Required methods
    fn assert_none(self) -> Self;
    fn debug_assert_none(self) -> Self;
}
Expand description

An extension trait to add the assertion_none methods.

Required Methods§

Source

fn assert_none(self) -> Self

Asserts the Option is None.

§Panics

If it is Some, the method panics.

§Examples
use chain_assertions::prelude::*;

let x: Option<i32> = None;
let x = x.assert_none().map(|v| v * 2);
assert_eq!(x, None);
use chain_assertions::prelude::*;

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

fn debug_assert_none(self) -> Self

Asserts the Option is None only in debug builds.

§Panics

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

§Examples
use chain_assertions::prelude::*;

let x: Option<i32> = None;
let x = x.debug_assert_none().map(|v| v * 2);
assert_eq!(x, None);

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> AssertNoneExt for Option<T>
where T: Debug,

Source§

fn assert_none(self) -> Self

Source§

fn debug_assert_none(self) -> Self

Implementors§