Trait assertor::OptionAssertion

source ·
pub trait OptionAssertion<T, R>{
    // Required methods
    fn is_none(&self) -> R
       where T: PartialEq + Debug;
    fn is_some(&self) -> R
       where T: PartialEq + Debug;
    fn has_value<B>(&self, expected: B) -> R
       where B: Borrow<T>,
             T: PartialEq + Debug;
    fn some(&self) -> Subject<'_, T, (), R>
       where T: PartialEq + Debug;
}
Expand description

Trait for option assertion.

§Example

use assertor::*;

assert_that!(Option::Some(1)).has_value(1);
assert_that!(Option::Some(1)).is_some();
assert_that!(Option::<usize>::None).is_none();
assert_that!(Option::Some("foobar")).some().starts_with("foo");

Required Methods§

source

fn is_none(&self) -> R
where T: PartialEq + Debug,

Checks the subject is Option::None.

source

fn is_some(&self) -> R
where T: PartialEq + Debug,

Checks the subject is Option::Some(_).

source

fn has_value<B>(&self, expected: B) -> R
where B: Borrow<T>, T: PartialEq + Debug,

Checks the subject is Option::Some(expected).

source

fn some(&self) -> Subject<'_, T, (), R>
where T: PartialEq + Debug,

Returns a new subject which is the value of the subject if the subject is Option::Some(_). Otherwise, it fails.

§Example
use assertor::*;

let value = Option::Some("foobar");
assert_that!(value).some().starts_with("foo");
assert_that!(value).some().ends_with("bar");

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T, R> OptionAssertion<T, R> for Subject<'_, Option<T>, (), R>