Skip to content

Commit

Permalink
Implement PartialEq, Eq and Hash 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 411234b
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions glib/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3454,6 +3454,29 @@ 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> Eq for WeakRef<T> {}

impl<T: ObjectType> hash::Hash for WeakRef<T> {
#[inline]
fn hash<H: hash::Hasher>(&self, state: &mut H) {
unsafe { self.0.priv_.p.hash(state) }
}
}

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 }
}
}

// 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 411234b

Please sign in to comment.