Manually implement traits on wgpu::Id (#3630)

This commit is contained in:
TheOnlyMrCat 2023-04-06 07:56:04 +10:00 committed by GitHub
parent fdbbd02c1e
commit 47a887ce0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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`.