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::types::{Changed, Comparable};
#[derive(
PartialEq,
Debug,
)]
pub struct StringChange(pub String, pub String);
impl Comparable for String {
type Desc = String;
fn describe(&self) -> Self::Desc {
self.to_string()
}
type Change = StringChange;
fn comparison(&self, other: &Self) -> Changed<Self::Change> {
if self != other {
Changed::Changed(StringChange(self.to_string(), other.to_string()))
} else {
Changed::Unchanged
}
}
}
impl Comparable for &str {
type Desc = <String as Comparable>::Desc;
fn describe(&self) -> Self::Desc {
self.to_string()
}
type Change = <String as Comparable>::Change;
fn comparison(&self, other: &Self) -> Changed<Self::Change> {
if self != other {
Changed::Changed(StringChange(self.to_string(), other.to_string()))
} else {
Changed::Unchanged
}
}
}