comparable/
string.rs

1use crate::types::{Changed, Comparable};
2
3#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4#[derive(PartialEq, Debug)]
5pub struct StringChange(pub String, pub String);
6
7impl Comparable for String {
8	type Desc = String;
9
10	fn describe(&self) -> Self::Desc {
11		self.to_string()
12	}
13
14	type Change = StringChange;
15
16	fn comparison(&self, other: &Self) -> Changed<Self::Change> {
17		if self != other {
18			Changed::Changed(StringChange(self.to_string(), other.to_string()))
19		} else {
20			Changed::Unchanged
21		}
22	}
23}
24
25impl Comparable for &str {
26	type Desc = <String as Comparable>::Desc;
27
28	fn describe(&self) -> Self::Desc {
29		self.to_string()
30	}
31
32	type Change = <String as Comparable>::Change;
33
34	fn comparison(&self, other: &Self) -> Changed<Self::Change> {
35		if self != other {
36			Changed::Changed(StringChange(self.to_string(), other.to_string()))
37		} else {
38			Changed::Unchanged
39		}
40	}
41}