Skip to content

Commit

Permalink
Manually implement traits on wgpu::Id (#3630)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOnlyMrCat authored Apr 5, 2023
1 parent fdbbd02 commit 47a887c
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4243,9 +4243,42 @@ impl Surface {
#[cfg(feature = "expose-ids")]
#[cfg_attr(docsrs, doc(cfg(feature = "expose-ids")))]
#[repr(transparent)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct Id<T>(core::num::NonZeroU64, std::marker::PhantomData<*mut T>);

#[cfg(feature = "expose-ids")]
impl<T> Clone for Id<T> {
fn clone(&self) -> Self {
*self
}
}

#[cfg(feature = "expose-ids")]
impl<T> Copy for Id<T> {}

#[cfg(feature = "expose-ids")]
impl<T> Debug for Id<T> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.debug_tuple("Id").field(&self.0).finish()
}
}

#[cfg(feature = "expose-ids")]
impl<T> PartialEq for Id<T> {
fn eq(&self, other: &Id<T>) -> bool {
self.0 == other.0
}
}

#[cfg(feature = "expose-ids")]
impl<T> Eq for Id<T> {}

#[cfg(feature = "expose-ids")]
impl<T> std::hash::Hash for Id<T> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.0.hash(state)
}
}

#[cfg(feature = "expose-ids")]
impl Adapter {
/// Returns a globally-unique identifier for this `Adapter`.
Expand Down

0 comments on commit 47a887c

Please sign in to comment.