fluent_assertions/assertions/
mod.rs

1use std::fmt::Display;
2
3pub mod bool_assertion;
4pub mod error_assertion;
5pub mod numeric_assertion;
6pub mod option_assertion;
7pub mod result_assertion;
8pub mod string_assertion;
9
10// General Should trait for all types
11pub trait Should: Sized {
12    fn should(self) -> Assertion<Self>;
13}
14
15// Implement Should for all types
16impl<T> Should for T {
17    fn should(self) -> Assertion<Self> {
18        Assertion { value: self }
19    }
20}
21
22// General Assertion struct
23pub struct Assertion<T> {
24    value: T,
25}
26
27/// General assertions for all types
28impl<T> Assertion<T>
29where
30    T: PartialEq + Display,
31{
32    pub fn be(&self, other: T) -> &Self {
33        assert!(
34            self.value == other,
35            "Expected value to be {}, but got {}",
36            other,
37            self.value
38        );
39        self
40    }
41
42    pub fn not_be(&self, other: T) -> &Self {
43        assert!(
44            self.value != other,
45            "Expected value to not be {}, but got {}",
46            other,
47            self.value
48        );
49        self
50    }
51}