Skip to content

Commit 0d57dd2

Browse files
author
Brendan Molloy
committed
Add PartialOrd and Ord to Vec
1 parent 186b2b5 commit 0d57dd2

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/vec.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use core::{fmt, hash, iter::FromIterator, mem::MaybeUninit, ops, ptr, slice};
1+
use core::{cmp::Ordering, fmt, hash, iter::FromIterator, mem::MaybeUninit, ops, ptr, slice};
22
use hash32;
33

44
/// A fixed capacity [`Vec`](https://doc.rust-lang.org/std/vec/struct.Vec.html)
@@ -764,6 +764,26 @@ where
764764
// Implements Eq if underlying data is Eq
765765
impl<T, const N: usize> Eq for Vec<T, N> where T: Eq {}
766766

767+
impl<T, const N: usize> PartialOrd for Vec<T, N>
768+
where
769+
T: PartialOrd,
770+
{
771+
#[inline]
772+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
773+
PartialOrd::partial_cmp(&**self, &**other)
774+
}
775+
}
776+
777+
impl<T, const N: usize> Ord for Vec<T, N>
778+
where
779+
T: Ord,
780+
{
781+
#[inline]
782+
fn cmp(&self, other: &Self) -> Ordering {
783+
Ord::cmp(&**self, &**other)
784+
}
785+
}
786+
767787
impl<T, const N: usize> ops::Deref for Vec<T, N> {
768788
type Target = [T];
769789

0 commit comments

Comments
 (0)