Skip to main content

ps_ecc/cow/implementations/
ord.rs

1use std::cmp::Ordering;
2
3use crate::Cow;
4
5impl Ord for Cow<'_> {
6    fn cmp(&self, other: &Self) -> Ordering {
7        (**self).cmp(&**other)
8    }
9}
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_ord_compares_content_across_variants() -> Result<(), TestError> {
21        let borrowed = Cow::Borrowed(b"b");
22        let owned = Cow::Owned(Buffer::from_slice(b"a")?.share());
23
24        assert!(borrowed > owned);
25        assert!(owned < borrowed);
26
27        Ok(())
28    }
29}