AssertOkExt

Trait AssertOkExt 

Source
pub trait AssertOkExt {
    // Required methods
    fn assert_ok(self) -> Self;
    fn debug_assert_ok(self) -> Self;
}
Expand description

An extension trait to add the assertion_ok methods.

Required Methods§

Source

fn assert_ok(self) -> Self

Asserts the Result is Ok.

§Panics

The method panics if it is Err and 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().map(|x| x * 2);
assert_eq!(x, Ok(42));
use chain_assertions::prelude::*;

let x: Result<i32, &str> = Err("oops");
let _ = x.assert_ok().map(|x| x * 2);
//        ^-- panics here
Source

fn debug_assert_ok(self) -> Self

Asserts the Result is Ok but check only in debug builds.

§Panics

The method panics if all following conditions are satisfied:

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

Otherwise, the method returns self as is.

§Examples
use chain_assertions::prelude::*;

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

Source§

fn assert_ok(self) -> Self

Source§

fn debug_assert_ok(self) -> Self

Implementors§