ps_ecc/cow/implementations/
partial_eq.rs1use crate::Cow;
2
3impl PartialEq for Cow<'_> {
4 fn eq(&self, other: &Self) -> bool {
5 **self == **other
6 }
7}
8
9impl Eq for Cow<'_> {}
10
11#[cfg(test)]
12mod tests {
13 use ps_buffer::Buffer;
14
15 use crate::Cow;
16
17 type TestError = Box<dyn std::error::Error>;
18
19 #[test]
20 fn test_eq_across_variants_with_same_content() -> Result<(), TestError> {
21 let borrowed = Cow::Borrowed(b"abc");
22 let owned = Cow::Owned(Buffer::from_slice(b"abc")?.share());
23
24 assert_eq!(borrowed, owned);
25
26 Ok(())
27 }
28
29 #[test]
30 fn test_ne_for_different_content() -> Result<(), TestError> {
31 let borrowed = Cow::Borrowed(b"abc");
32 let owned = Cow::Owned(Buffer::from_slice(b"abd")?.share());
33
34 assert_ne!(borrowed, owned);
35
36 Ok(())
37 }
38}