Skip to content

Commit e685b2a

Browse files
committed
impl PartialOrd + Ord for Gc
1 parent cd42614 commit e685b2a

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/lib.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ use core::ptr::{NonNull, Pointee, DynMetadata};
5656
use core::marker::{PhantomData, Unsize};
5757
use core::hash::{Hash, Hasher};
5858
use core::fmt::{self, Debug, Formatter};
59+
use core::cmp::Ordering;
5960

6061
use zerogc_derive::unsafe_gc_impl;
6162
pub use zerogc_derive::{Trace, NullTrace};
@@ -835,13 +836,39 @@ impl<'gc, T: GcSafe<'gc, Id> + PartialEq + 'gc, Id: CollectorId> PartialEq for G
835836
// NOTE: We compare by value, not identity
836837
self.value() == other.value()
837838
}
839+
#[inline]
840+
fn ne(&self, other: &Self) -> bool {
841+
self.value() != other.value()
842+
}
838843
}
839844
impl<'gc, T: GcSafe<'gc, Id> + Eq + 'gc, Id: CollectorId> Eq for Gc<'gc, T, Id> {}
840845
impl<'gc, T: GcSafe<'gc, Id> + PartialEq + 'gc, Id: CollectorId> PartialEq<T> for Gc<'gc, T, Id> {
841846
#[inline]
842847
fn eq(&self, other: &T) -> bool {
843848
self.value() == other
844849
}
850+
#[inline]
851+
fn ne(&self, other: &T) -> bool {
852+
self.value() != other
853+
}
854+
}
855+
impl<'gc, T: GcSafe<'gc, Id> + PartialOrd + 'gc, Id: CollectorId> PartialOrd for Gc<'gc, T, Id> {
856+
#[inline]
857+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
858+
self.value().partial_cmp(other.value())
859+
}
860+
}
861+
impl<'gc, T: GcSafe<'gc, Id> + PartialOrd + 'gc, Id: CollectorId> PartialOrd<T> for Gc<'gc, T, Id> {
862+
#[inline]
863+
fn partial_cmp(&self, other: &T) -> Option<Ordering> {
864+
self.value().partial_cmp(other)
865+
}
866+
}
867+
impl<'gc, T: GcSafe<'gc, Id> + Ord + 'gc, Id: CollectorId> Ord for Gc<'gc, T, Id> {
868+
#[inline]
869+
fn cmp(&self, other: &Self) -> Ordering {
870+
self.value().cmp(other)
871+
}
845872
}
846873
impl<'gc, T: GcSafe<'gc, Id> + Debug + 'gc, Id: CollectorId> Debug for Gc<'gc, T, Id> {
847874
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {

0 commit comments

Comments
 (0)