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, ToBe},
Matcher, TypedMatcher,
};
use std::fmt::Debug;
/// Creates a matcher that matches empty values
///
/// # Examples
///
/// ```
/// use caramelo::expect;
/// use caramelo::matchers::empty;
///
/// expect("").to_be(empty());
/// ```
pub fn empty() -> Empty {
Empty
}
/// Matcher that matches empty values
pub struct Empty;
impl<T> Matcher<T> for Empty
where
T: PartialEq + Default + Debug,
{
fn matches(&self, value: &T) -> bool {
*value == T::default()
}
fn description(&self) -> String {
"empty".to_owned()
}
}
impl<T> TypedMatcher<T> for Empty
where
T: PartialEq + Default + Debug,
{
fn matcher_type(&self) -> MatchType {
ToBe
}
}