diff options
| author | Josh Stone <jistone@redhat.com> | 2024-01-17 15:39:45 -0800 |
|---|---|---|
| committer | Josh Stone <jistone@redhat.com> | 2024-01-19 20:10:38 -0800 |
| commit | cb7d863e742ae3782174db2acf57310cd1b27561 (patch) | |
| tree | c649e5f4b4702a13e01345ecc1736ebf39beb8f7 /compiler/rustc_data_structures/src | |
| parent | 0547c41f906760ce117a55ca690820b44d8e7eef (diff) | |
| download | rust-cb7d863e742ae3782174db2acf57310cd1b27561.tar.gz rust-cb7d863e742ae3782174db2acf57310cd1b27561.zip | |
Add Pu128 = #[repr(packed(8))] u128
Diffstat (limited to 'compiler/rustc_data_structures/src')
| -rw-r--r-- | compiler/rustc_data_structures/src/lib.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_data_structures/src/packed.rs | 71 |
2 files changed, 72 insertions, 0 deletions
diff --git a/compiler/rustc_data_structures/src/lib.rs b/compiler/rustc_data_structures/src/lib.rs index 93b4032c310..077e90350a3 100644 --- a/compiler/rustc_data_structures/src/lib.rs +++ b/compiler/rustc_data_structures/src/lib.rs @@ -93,6 +93,7 @@ pub mod aligned; pub mod frozen; mod hashes; pub mod owned_slice; +pub mod packed; pub mod sso; pub mod steal; pub mod tagged_ptr; diff --git a/compiler/rustc_data_structures/src/packed.rs b/compiler/rustc_data_structures/src/packed.rs new file mode 100644 index 00000000000..b8d4b295dfa --- /dev/null +++ b/compiler/rustc_data_structures/src/packed.rs @@ -0,0 +1,71 @@ +use crate::stable_hasher::{HashStable, StableHasher}; +use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; +use std::cmp::Ordering; +use std::fmt; + +#[repr(packed(8))] +#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct Pu128(pub u128); + +impl Pu128 { + #[inline] + pub fn get(self) -> u128 { + self.0 + } +} + +impl From<u128> for Pu128 { + #[inline] + fn from(value: u128) -> Self { + Self(value) + } +} + +impl PartialEq<u128> for Pu128 { + #[inline] + fn eq(&self, other: &u128) -> bool { + ({ self.0 }) == *other + } +} + +impl PartialOrd<u128> for Pu128 { + #[inline] + fn partial_cmp(&self, other: &u128) -> Option<Ordering> { + { self.0 }.partial_cmp(other) + } +} + +impl fmt::Display for Pu128 { + #[inline] + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + { self.0 }.fmt(f) + } +} + +impl fmt::UpperHex for Pu128 { + #[inline] + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + { self.0 }.fmt(f) + } +} + +impl<CTX> HashStable<CTX> for Pu128 { + #[inline] + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + { self.0 }.hash_stable(ctx, hasher) + } +} + +impl<S: Encoder> Encodable<S> for Pu128 { + #[inline] + fn encode(&self, s: &mut S) { + { self.0 }.encode(s); + } +} + +impl<D: Decoder> Decodable<D> for Pu128 { + #[inline] + fn decode(d: &mut D) -> Self { + Self(u128::decode(d)) + } +} |
