diffus/
same.rs

1use crate::Same;
2
3impl<T: Same> Same for Option<T> {
4    fn same(&self, other: &Self) -> bool {
5        match (self, other) {
6            (Some(a), Some(b)) => a.same(b),
7            (None, None) => true,
8            _ => false,
9        }
10    }
11}
12
13macro_rules! same_for_eq {
14    ($($typ:ty),*) => {
15        $(
16            impl Same for $typ {
17                fn same(&self, other: &Self) -> bool {
18                    self == other
19                }
20            }
21        )*
22    }
23}
24
25same_for_eq! { i64, i32, i16, i8, u64, u32, u16, u8, char, str, bool, isize, usize, () }
26
27macro_rules! same_for_float {
28    ($($typ:ty),*) => {
29        $(
30            impl Same for $typ {
31                fn same(&self, other: &Self) -> bool {
32                    self.to_ne_bytes() == other.to_ne_bytes()
33                }
34            }
35        )*
36    }
37}
38
39same_for_float! { f32, f64 }
40
41#[cfg(feature = "snake_case-impl")]
42same_for_eq! { snake_case::SnakeCase }
43
44#[cfg(feature = "uuid-impl")]
45same_for_eq! { uuid::Uuid }
46
47impl<T: Same + ?Sized> Same for &T {
48    fn same(&self, other: &Self) -> bool {
49        (*self).same(*other)
50    }
51}