diff options
| author | Ben Kimock <kimockb@gmail.com> | 2025-02-15 15:18:19 -0500 | 
|---|---|---|
| committer | Ben Kimock <kimockb@gmail.com> | 2025-02-16 16:18:30 -0500 | 
| commit | 4cf21866e8f18449ea0c41ee1ba031c05419d94c (patch) | |
| tree | 1bb6febab86e57c90e368461886364404a60cf0f /compiler/rustc_serialize/src | |
| parent | 1d7cf0ff407beea447334c2784d39658e4be3ca0 (diff) | |
| download | rust-4cf21866e8f18449ea0c41ee1ba031c05419d94c.tar.gz rust-4cf21866e8f18449ea0c41ee1ba031c05419d94c.zip | |
Move hashes from rustc_data_structure to rustc_hashes so they can be shared with rust-analyzer
Diffstat (limited to 'compiler/rustc_serialize/src')
| -rw-r--r-- | compiler/rustc_serialize/src/serialize.rs | 29 | 
1 files changed, 29 insertions, 0 deletions
| diff --git a/compiler/rustc_serialize/src/serialize.rs b/compiler/rustc_serialize/src/serialize.rs index db8555edd0f..1eefd76f92b 100644 --- a/compiler/rustc_serialize/src/serialize.rs +++ b/compiler/rustc_serialize/src/serialize.rs @@ -10,6 +10,7 @@ use std::path; use std::rc::Rc; use std::sync::Arc; +use rustc_hashes::{Hash64, Hash128}; use smallvec::{Array, SmallVec}; use thin_vec::ThinVec; @@ -716,3 +717,31 @@ impl<D: Decoder, T: Decodable<D>> Decodable<D> for Arc<[T]> { vec.into() } } + +impl<S: Encoder> Encodable<S> for Hash64 { + #[inline] + fn encode(&self, s: &mut S) { + s.emit_raw_bytes(&self.as_u64().to_le_bytes()); + } +} + +impl<S: Encoder> Encodable<S> for Hash128 { + #[inline] + fn encode(&self, s: &mut S) { + s.emit_raw_bytes(&self.as_u128().to_le_bytes()); + } +} + +impl<D: Decoder> Decodable<D> for Hash64 { + #[inline] + fn decode(d: &mut D) -> Self { + Self::new(u64::from_le_bytes(d.read_raw_bytes(8).try_into().unwrap())) + } +} + +impl<D: Decoder> Decodable<D> for Hash128 { + #[inline] + fn decode(d: &mut D) -> Self { + Self::new(u128::from_le_bytes(d.read_raw_bytes(16).try_into().unwrap())) + } +} | 
