Skip to content

Commit

Permalink
Implement PartialEq and PartialOrd for WeakRef
Browse files Browse the repository at this point in the history
  • Loading branch information
andy128k committed Feb 17, 2023
1 parent 1fddbfd commit d583398
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions glib/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3454,6 +3454,27 @@ impl<T: ObjectType> Default for WeakRef<T> {
unsafe impl<T: ObjectType + Sync + Sync> Sync for WeakRef<T> {}
unsafe impl<T: ObjectType + Send + Sync> Send for WeakRef<T> {}

impl<T: ObjectType> PartialEq for WeakRef<T> {
#[inline]
fn eq(&self, other: &Self) -> bool {
unsafe { self.0.priv_.p == other.0.priv_.p }
}
}

impl<T: ObjectType> PartialEq<T> for WeakRef<T> {
#[inline]
fn eq(&self, other: &T) -> bool {
unsafe { self.0.priv_.p == other.as_ptr() as *mut std::os::raw::c_void }
}
}

impl<T: ObjectType> PartialOrd for WeakRef<T> {
#[inline]
fn partial_cmp(&self, other: &T) -> Option<Ordering> {
unsafe { self.0.priv_.p.partial_cmp(other.0.priv_.p) }
}
}

// rustdoc-stripper-ignore-next
/// A weak reference to the object it was created for that can be sent to
/// different threads even for object types that don't implement `Send`.
Expand Down

0 comments on commit d583398

Please sign in to comment.