stavec/
cmp.rs

1use crate::{
2    traits::{Container, Length},
3    GenericVec,
4};
5use core::cmp::Ordering;
6
7impl<C: Container + ?Sized, L: Length> PartialOrd for GenericVec<C, L>
8where
9    C::Item: PartialOrd,
10{
11    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
12        self.as_slice().partial_cmp(other.as_slice())
13    }
14}
15
16impl<C: Container + ?Sized, L: Length> Ord for GenericVec<C, L>
17where
18    C::Item: Ord,
19{
20    fn cmp(&self, other: &Self) -> Ordering {
21        self.as_slice().cmp(other.as_slice())
22    }
23}
24
25impl<C: Container + ?Sized, L: Length> PartialEq for GenericVec<C, L>
26where
27    C::Item: PartialEq,
28{
29    fn eq(&self, other: &Self) -> bool {
30        self.as_slice().eq(other.as_slice())
31    }
32}
33
34impl<C: Container + ?Sized, L: Length> Eq for GenericVec<C, L> where C::Item: Eq {}
35
36impl<const M: usize, C: Container + ?Sized, L: Length> PartialEq<[C::Item; M]> for GenericVec<C, L>
37where
38    C::Item: PartialEq,
39{
40    fn eq(&self, other: &[C::Item; M]) -> bool {
41        self.as_slice().eq(&other[..])
42    }
43}
44
45impl<C: Container + ?Sized, L: Length> PartialEq<[C::Item]> for GenericVec<C, L>
46where
47    C::Item: PartialEq,
48{
49    fn eq(&self, other: &[C::Item]) -> bool {
50        self.as_slice().eq(other)
51    }
52}
53
54impl<C: Container + ?Sized, L: Length> PartialEq<&[C::Item]> for GenericVec<C, L>
55where
56    C::Item: PartialEq,
57{
58    fn eq(&self, other: &&[C::Item]) -> bool {
59        self.as_slice().eq(*other)
60    }
61}
62
63impl<C: Container + ?Sized, L: Length> PartialEq<&mut [C::Item]> for GenericVec<C, L>
64where
65    C::Item: PartialEq,
66{
67    fn eq(&self, other: &&mut [C::Item]) -> bool {
68        self.as_slice().eq(*other)
69    }
70}
71
72#[cfg(feature = "std")]
73impl<C: Container + ?Sized, L: Length> PartialEq<std::vec::Vec<C::Item>> for GenericVec<C, L>
74where
75    C::Item: PartialEq,
76{
77    fn eq(&self, other: &std::vec::Vec<C::Item>) -> bool {
78        self.as_slice().eq(other.as_slice())
79    }
80}