Skip to main content

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

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

fn debug_assert_none(self) -> Self

Asserts the Option is None only in debug builds.

§Panics

The method panics if all following conditions are satisfied:

  • It is Some
  • debug_assertions is enabled
  • passthrough feature is disabled

Otherwise, the method returns self as is.

§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".

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§