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
use std::fmt::{Display, Formatter};
use crate::Actual;
impl<T> Actual<T> {
pub fn new(value: T, description_func: fn(&T) -> String) -> Actual<T> {
Actual {
value,
description_func,
}
}
}
impl<T> Actual<T>
where
T: Display,
{
pub fn create_for(value: T) -> Actual<T> {
Actual {
value,
description_func: |v| v.to_string(),
}
}
}
impl<T> Display for Actual<T> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", (self.description_func)(&self.value))
}
}
impl<T> PartialEq for Actual<T>
where
T: PartialEq,
{
fn eq(&self, other: &Self) -> bool {
self.value.eq(&other.value)
}
fn ne(&self, other: &Self) -> bool {
self.value.ne(&other.value)
}
}