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

If it is Err, the method panics.

§Examples
use chain_assertions::prelude::*;

let x: Result<i32, &str> = Ok(21);
let x = x.assert_ok().map(|v| v * 2);
assert_eq!(x, Ok(42));
use chain_assertions::prelude::*;

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

fn debug_assert_ok(self) -> Self

Asserts the Result is Ok only in debug builds.

§Panics

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

§Examples
use chain_assertions::prelude::*;

let x: Result<i32, &str> = Ok(21);
let x = x.debug_assert_ok().map(|v| v * 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§