AssertErrExt

Trait AssertErrExt 

Source
pub trait AssertErrExt {
    // Required methods
    fn assert_err(self) -> Self;
    fn debug_assert_err(self) -> Self;
}
Expand description

An extension trait to add the assertion_err methods.

Required Methods§

Source

fn assert_err(self) -> Self

Asserts the Result is Err.

§Panics

If it is Ok, the method panics.

§Examples

This sample

use chain_assertions::prelude::*;

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

let x: Result<&str, i32> = Ok("success");
let _ = x.assert_err().map_err(|v| v * 2);
//        ^-- panics here
Source

fn debug_assert_err(self) -> Self

Asserts the Result is Err only in debug builds.

§Panics

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

§Examples
use chain_assertions::prelude::*;

let x: Result<&str, i32> = Err(42);
let _ = x.debug_assert_err();

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> AssertErrExt for Result<T, E>
where T: Debug,

Source§

fn assert_err(self) -> Self

Source§

fn debug_assert_err(self) -> Self

Implementors§