rustc_data_structures/
svh.rs1use std::fmt;
9
10use rustc_macros::{Decodable_NoContext, Encodable_NoContext, StableHash};
11
12use crate::fingerprint::Fingerprint;
13
14#[derive(#[automatically_derived]
impl ::core::marker::Copy for Svh { }Copy, #[automatically_derived]
impl ::core::clone::Clone for Svh {
#[inline]
fn clone(&self) -> Svh {
let _: ::core::clone::AssertParamIsClone<Fingerprint>;
*self
}
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for Svh {
#[inline]
fn eq(&self, other: &Svh) -> bool { self.hash == other.hash }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for Svh {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Fingerprint>;
}
}Eq, #[automatically_derived]
impl ::core::fmt::Debug for Svh {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field1_finish(f, "Svh", "hash",
&&self.hash)
}
}Debug, #[automatically_derived]
impl ::core::hash::Hash for Svh {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.hash, state)
}
}Hash)]
15#[derive(const _: () =
{
impl<__E: ::rustc_serialize::Encoder>
::rustc_serialize::Encodable<__E> for Svh {
fn encode(&self, __encoder: &mut __E) {
match *self {
Svh { hash: ref __binding_0 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
}
}
}
};Encodable_NoContext, const _: () =
{
impl<__D: ::rustc_serialize::Decoder>
::rustc_serialize::Decodable<__D> for Svh {
fn decode(__decoder: &mut __D) -> Self {
Svh { hash: ::rustc_serialize::Decodable::decode(__decoder) }
}
}
};Decodable_NoContext, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for Svh {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
Svh { hash: ref __binding_0 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash)]
16pub struct Svh {
17 hash: Fingerprint,
18}
19
20impl Svh {
21 pub fn new(hash: Fingerprint) -> Svh {
25 Svh { hash }
26 }
27
28 pub fn as_u128(self) -> u128 {
29 self.hash.as_u128()
30 }
31
32 pub fn to_hex(self) -> String {
33 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0:032x}", self.hash.as_u128()))
})format!("{:032x}", self.hash.as_u128())
34 }
35}
36
37impl fmt::Display for Svh {
38 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39 f.pad(&self.to_hex())
40 }
41}