rustc_data_structures/
svh.rsuse std::fmt;
use rustc_macros::{Decodable_Generic, Encodable_Generic};
use crate::fingerprint::Fingerprint;
use crate::stable_hasher;
#[derive(Copy, Clone, PartialEq, Eq, Debug, Encodable_Generic, Decodable_Generic, Hash)]
pub struct Svh {
hash: Fingerprint,
}
impl Svh {
pub fn new(hash: Fingerprint) -> Svh {
Svh { hash }
}
pub fn as_u128(self) -> u128 {
self.hash.as_u128()
}
pub fn to_hex(self) -> String {
format!("{:032x}", self.hash.as_u128())
}
}
impl fmt::Display for Svh {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.pad(&self.to_hex())
}
}
impl<T> stable_hasher::HashStable<T> for Svh {
#[inline]
fn hash_stable(&self, ctx: &mut T, hasher: &mut stable_hasher::StableHasher) {
let Svh { hash } = *self;
hash.hash_stable(ctx, hasher);
}
}