CowAssertion

Trait CowAssertion 

Source
pub trait CowAssertion<T: ?Sized, Y, R> {
    // Required methods
    fn is_borrowed(&self) -> R;
    fn is_owned(&self) -> R;
    fn deref(&self) -> Subject<'_, Y, (), R>;
}
Expand description

Trait for Cow assertion.

§Example

use std::borrow::Cow;
use assertor::*;

assert_that!(Cow::Borrowed("foobar")).is_borrowed();
assert_that!(Cow::<str>::Owned("foobar".to_string())).is_owned();
assert_that!(Cow::<str>::Owned("foobar".to_string())).deref().is_same_string_to("foobar");

Required Methods§

Source

fn is_borrowed(&self) -> R

Checks that the subject is Cow::Borrowed(_).

Source

fn is_owned(&self) -> R

Checks that the subject is Cow::Owned(_).

Source

fn deref(&self) -> Subject<'_, Y, (), R>

Returns a new subject which is the dereferenced value of the subject.

§Example
use std::borrow::Cow;
use assertor::*;

let owned: Cow<str> = Cow::Owned("owned".to_string());
let borrowed: Cow<str> = Cow::Borrowed("borrowed");
assert_that!(owned).deref().is_same_string_to("owned");
assert_that!(borrowed).deref().is_same_string_to("borrowed");

let cow_float_value: Cow<f32> = Cow::Owned(1.23);
assert_that!(cow_float_value).deref().is_approx_equal_to(1.23);

Implementors§

Source§

impl<'a, T, Y, R> CowAssertion<T, Y, R> for Subject<'a, Cow<'a, T>, (), R>
where T: ToOwned<Owned = Y> + ?Sized, AssertionResult: AssertionStrategy<R>,