1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use crate::{
MatchType::{self, To},
Matcher, TypedMatcher,
};
use std::fmt::Debug;
/// Creates a matcher that matches values not equal to the given value
///
/// # Examples
///
/// ```
/// use caramelo::expect;
/// use caramelo::matchers::ne;
///
/// expect(5).to(ne(3));
/// ```
pub fn ne<T>(value: T) -> NotEqual<T> {
NotEqual(value)
}
/// Matcher that matches values not equal to the given value
pub struct NotEqual<T>(T);
impl<T> Matcher<T> for NotEqual<T>
where
T: PartialEq + Debug,
{
fn matches(&self, value: &T) -> bool {
self.0 != *value
}
fn description(&self) -> String {
format!("not equal to {:?}", self.0)
}
}
impl<T> TypedMatcher<T> for NotEqual<T>
where
T: PartialEq + Debug,
{
fn matcher_type(&self) -> MatchType {
To
}
}