splinter_rs/splinter/
cmp.rs

1use crate::cow::CowSplinter;
2
3use super::{Splinter, SplinterRef};
4
5// Splinter == Splinter
6impl PartialEq for Splinter {
7    fn eq(&self, other: &Self) -> bool {
8        self.partitions == other.partitions
9    }
10}
11
12// Splinter == SplinterRef
13impl<T: AsRef<[u8]>> PartialEq<SplinterRef<T>> for Splinter {
14    fn eq(&self, other: &SplinterRef<T>) -> bool {
15        self.partitions == other.load_partitions()
16    }
17}
18
19// Splinter == CowSplinter
20impl<T: AsRef<[u8]>> PartialEq<CowSplinter<T>> for Splinter {
21    fn eq(&self, other: &CowSplinter<T>) -> bool {
22        other == self
23    }
24}
25
26// SplinterRef == SplinterRef
27impl<T1: AsRef<[u8]>, T2: AsRef<[u8]>> PartialEq<SplinterRef<T2>> for SplinterRef<T1> {
28    fn eq(&self, other: &SplinterRef<T2>) -> bool {
29        self.load_partitions() == other.load_partitions()
30    }
31}
32
33// SplinterRef == Splinter
34impl<T: AsRef<[u8]>> PartialEq<Splinter> for SplinterRef<T> {
35    fn eq(&self, other: &Splinter) -> bool {
36        other == self
37    }
38}
39
40// SplinterRef == CowSplinter
41impl<T1: AsRef<[u8]>, T2: AsRef<[u8]>> PartialEq<CowSplinter<T2>> for SplinterRef<T1> {
42    fn eq(&self, other: &CowSplinter<T2>) -> bool {
43        other == self
44    }
45}
46
47// CowSplinter == CowSplinter
48impl<T: AsRef<[u8]>> PartialEq for CowSplinter<T> {
49    fn eq(&self, other: &Self) -> bool {
50        use CowSplinter::*;
51        match (self, other) {
52            (Ref(left), Ref(right)) => left == right,
53            (Ref(left), Owned(right)) => right == left,
54            (Owned(left), Ref(right)) => left == right,
55            (Owned(left), Owned(right)) => left == right,
56        }
57    }
58}
59
60// CowSplinter == Splinter
61impl<T: AsRef<[u8]>> PartialEq<Splinter> for CowSplinter<T> {
62    fn eq(&self, right: &Splinter) -> bool {
63        use CowSplinter::*;
64        match self {
65            Ref(left) => right == left,
66            Owned(left) => left == right,
67        }
68    }
69}
70
71// CowSplinter == SplinterRef
72impl<T1: AsRef<[u8]>, T2: AsRef<[u8]>> PartialEq<SplinterRef<T2>> for CowSplinter<T1> {
73    fn eq(&self, other: &SplinterRef<T2>) -> bool {
74        use CowSplinter::*;
75        match self {
76            Ref(left) => left == other,
77            Owned(left) => left == other,
78        }
79    }
80}