Skip to main content

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(|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 here
Source

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_assertions is enabled
  • passthrough feature 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".

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§