sync: implement PartialEq and Eq for CancellationToken (#8110)

Co-authored-by: Martin Tzvetanov Grigorov <[email protected]>
This commit is contained in:
Timo
2026-05-05 13:46:35 +02:00
committed by GitHub
co-authored by Martin Tzvetanov Grigorov
parent e56ff72fe7
commit 02ff0833e0
2 changed files with 70 additions and 0 deletions
+20
View File
@@ -122,6 +122,26 @@ impl Clone for CancellationToken {
}
}
impl PartialEq for CancellationToken {
/// Checks if two tokens are equal in terms of their cancellation operation.
///
/// Two tokens are considered equal if cancelling one will always also cancel the other and vice
/// versa. This is only true for cloned tokens and not for tokens in a parent-child
/// relationship.
fn eq(&self, other: &CancellationToken) -> bool {
Arc::ptr_eq(&self.inner, &other.inner)
}
}
impl Eq for CancellationToken {}
impl core::hash::Hash for CancellationToken {
#[inline]
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
Arc::as_ptr(&self.inner).hash(state);
}
}
impl Drop for CancellationToken {
fn drop(&mut self) {
tree_node::decrease_handle_refcount(&self.inner);