Skip to content

Commit cfbf0f3

Browse files
committed
libc: add PartialEq, Eq, and trait implementations for Padding.
1 parent eda627e commit cfbf0f3

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/types.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Platform-agnostic support types.
22
3+
#[cfg(feature = "extra_traits")]
4+
use core::hash::Hash;
35
use core::mem::MaybeUninit;
46

57
use crate::prelude::*;
@@ -30,6 +32,24 @@ impl<T: Copy> fmt::Debug for Padding<T> {
3032
}
3133
}
3234

35+
/// Do nothing when hashing to ignore the existence of padding fields.
36+
#[cfg(feature = "extra_traits")]
37+
impl<T: Copy> Hash for Padding<T> {
38+
fn hash<H: hash::Hasher>(&self, _state: &mut H) {}
39+
}
40+
41+
/// Padding fields are all equal, regardless of what is inside them, so they do not affect anything.
42+
#[cfg(feature = "extra_traits")]
43+
impl<T: Copy> PartialEq for Padding<T> {
44+
fn eq(&self, _other: &Self) -> bool {
45+
true
46+
}
47+
}
48+
49+
/// Mark that `Padding` implements `Eq` so that it can be used in types that implement it.
50+
#[cfg(feature = "extra_traits")]
51+
impl<T: Copy> Eq for Padding<T> {}
52+
3353
/// The default repr type used for C style enums in Rust.
3454
#[cfg(target_env = "msvc")]
3555
#[allow(unused)]

0 commit comments

Comments
 (0)