Function faux::matcher::eq[][src]

pub fn eq<Arg, Expected>(expected: Expected) -> impl ArgMatcher<Arg> where
    Arg: Borrow<Expected>,
    Expected: Debug + PartialEq

Returns an equality matcher.

Returns a matcher that compares Arg using equality across borrows.

Unlike eq_against, it only allows equality matching for the same type. This comes at the benefit of being able to match across borrows.

Examples

Basic usage

use faux::matcher::{self, ArgMatcher};

let eq_four = matcher::eq(4);
assert!(eq_four.matches(&4));
assert!(!eq_four.matches(&5));

Matching across borrows

use std::rc::Rc;
use faux::matcher::{self, ArgMatcher};

// `Rc<T>` implements `Borrow<T>`
assert!(matcher::eq(5).matches(&Rc::new(5)));

// `&T` implements `Borrow<T>`
let ref_of_ref: &&i32 = &&5;
assert!(matcher::eq(5).matches(ref_of_ref));