From 0dacac239afdda094c229e5cc338796da8be3a05 Mon Sep 17 00:00:00 2001 From: sagudev <16504129+sagudev@users.noreply.github.com> Date: Tue, 28 Jul 2026 07:55:26 +0200 Subject: [PATCH] `impl_eq_ord_hash_box_address` Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --- wgpu/src/cmp.rs | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/wgpu/src/cmp.rs b/wgpu/src/cmp.rs index c2ec1265e..3c733f388 100644 --- a/wgpu/src/cmp.rs +++ b/wgpu/src/cmp.rs @@ -105,5 +105,50 @@ macro_rules! impl_eq_ord_hash_arc_address { }; } +/// Implements `PartialEq`, `Eq`, `PartialOrd`, `Ord`, and `Hash` for a type by comparing the addresses of the `Arc`s. +/// +/// ```ignore +/// impl_eq_ord_hash_arc_address!(MyType => .field); +/// ``` +#[cfg_attr(not(any(wgpu_core, custom)), expect(unused_macros))] +macro_rules! impl_eq_ord_hash_box_address { + ($type:ty => $($access:tt)*) => { + impl PartialEq for $type { + fn eq(&self, other: &Self) -> bool { + let address_left: *const _ = &self $($access)*; + let address_right: *const _ = &other $($access)*; + + address_left == address_right + } + } + + impl Eq for $type {} + + impl PartialOrd for $type { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } + } + + impl Ord for $type { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + let address_left: *const _ = &self $($access)*; + let address_right: *const _ = &other $($access)*; + + address_left.cmp(&address_right) + } + } + + impl core::hash::Hash for $type { + fn hash(&self, state: &mut H) { + let address: *const _ = &self $($access)*; + address.hash(state) + } + } + }; +} + #[cfg_attr(not(any(wgpu_core, custom)), expect(unused_imports))] -pub(crate) use {impl_eq_ord_hash_arc_address, impl_eq_ord_hash_proxy}; +pub(crate) use { + impl_eq_ord_hash_arc_address, impl_eq_ord_hash_box_address, impl_eq_ord_hash_proxy, +};