AssertOkAndExt

Trait AssertOkAndExt 

Source
pub trait AssertOkAndExt<T> {
    // Required methods
    fn assert_ok_and(self, cond: impl FnOnce(&T) -> bool) -> Self;
    fn debug_assert_ok_and(self, cond: impl FnOnce(&T) -> bool) -> Self;
}
Expand description

An extension trait to add the assertion_ok_and methods.

Required Methods§

Source

fn assert_ok_and(self, cond: impl FnOnce(&T) -> bool) -> Self

Asserts the Result is Ok and satisfies the condition.

§Panics

The method panics if all following conditions are satisfied:

  • It is Err, or Ok but user-provided condition returns false
  • debug_assertions is enabled
  • passthrough feature is disabled

Otherwise, the method return self as is.

§Examples
use chain_assertions::prelude::*;

let x: Result<i32, &str> = Ok(21);
let x = x.assert_ok_and(|x| x == &21).map(|x| x * 2);
assert_eq!(x, Ok(42), "Expected Ok(42)");
Source

fn debug_assert_ok_and(self, cond: impl FnOnce(&T) -> bool) -> Self

Asserts the Result is Ok and satisfies the condition only in debug builds.

§Panics

The method panics if all following conditions are satisfied:

  • It is Err, or Ok but user-provided condition returns false
  • debug_assertions is enabled
  • passthrough feature is disabled

Otherwise, the method return self as is.

§Examples
use chain_assertions::prelude::*;

let x: Result<i32, &str> = Ok(21);
let x = x.debug_assert_ok_and(|x| x == &21).map(|x| x * 2);
assert_eq!(x, Ok(42), "Expected Ok(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, E> AssertOkAndExt<T> for Result<T, E>
where T: Debug, E: Debug,

Source§

fn assert_ok_and(self, cond: impl FnOnce(&T) -> bool) -> Self

Source§

fn debug_assert_ok_and(self, _cond: impl FnOnce(&T) -> bool) -> Self

Implementors§