rustc_data_structures/
svh.rs1use std::fmt;
9
10use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext};
11
12use crate::fingerprint::Fingerprint;
13
14#[derive(
15 #[automatically_derived]
impl ::core::marker::Copy for Svh { }Copy,
16 #[automatically_derived]
impl ::core::clone::Clone for Svh {
#[inline]
fn clone(&self) -> Svh {
let _: ::core::clone::AssertParamIsClone<Fingerprint>;
*self
}
}Clone,
17 #[automatically_derived]
impl ::core::cmp::PartialEq for Svh {
#[inline]
fn eq(&self, other: &Svh) -> bool { self.hash == other.hash }
}PartialEq,
18 #[automatically_derived]
impl ::core::cmp::Eq for Svh {
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Fingerprint>;
}
}Eq,
19 #[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,
20 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,
21 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,
22 #[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,
23 const _: () =
{
impl<__CTX> ::rustc_data_structures::stable_hasher::HashStable<__CTX>
for Svh {
#[inline]
fn hash_stable(&self, __hcx: &mut __CTX,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
Svh { hash: ref __binding_0 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable_NoContext
24)]
25pub struct Svh {
26 hash: Fingerprint,
27}
28
29impl Svh {
30 pub fn new(hash: Fingerprint) -> Svh {
34 Svh { hash }
35 }
36
37 pub fn as_u128(self) -> u128 {
38 self.hash.as_u128()
39 }
40
41 pub fn to_hex(self) -> String {
42 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0:032x}", self.hash.as_u128()))
})format!("{:032x}", self.hash.as_u128())
43 }
44}
45
46impl fmt::Display for Svh {
47 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48 f.pad(&self.to_hex())
49 }
50}