Struct Hash
pub struct Hash(/* private field */);
An output of the default size, 32 bytes, which provides constant-time equality checking.
Hash implements From and Into for [u8; 32], and it provides
from_bytes and as_bytes for explicit conversions between itself and
[u8; 32]. However, byte arrays and slices don't provide constant-time
equality checking, which is often a security requirement in software that
handles private data. Hash doesn't implement Deref or AsRef, to
avoid situations where a type conversion happens implicitly and the
constant-time property is accidentally lost.
Hash provides the to_hex and from_hex methods for converting to
and from hexadecimal. It also implements Display and FromStr.
Implementations
impl Hash
const fn as_bytes(&self) -> &[u8; 32]The raw bytes of the
Hash. Note that byte arrays don't provide constant-time equality checking, so if you need to compare hashes, prefer theHashtype.const fn from_bytes(bytes: [u8; 32]) -> SelfCreate a
Hashfrom its raw bytes representation.const fn as_slice(&self) -> &[u8]The raw bytes of the
Hash, as a slice. Useful for serialization. Note that byte arrays don't provide constant-time equality checking, so if you need to compare hashes, prefer theHashtype.fn from_slice(bytes: &[u8]) -> Result<Self, TryFromSliceError>Create a
Hashfrom its raw bytes representation as a slice.Returns an error if the slice is not exactly 32 bytes long.
fn to_hex(&self) -> ArrayString<{ _ }>Encode a
Hashin lowercase hexadecimal.The returned
ArrayStringis a fixed size and doesn't allocate memory on the heap. Note thatArrayStringdoesn't provide constant-time equality checking, so if you need to compare hashes, prefer theHashtype.fn from_hex(hex: impl AsRef<[u8]>) -> Result<Self, HexError>Decode a
Hashfrom hexadecimal. Both uppercase and lowercase ASCII bytes are supported.Any byte outside the ranges
'0'...'9','a'...'f', and'A'...'F'results in an error. An input length other than 64 also results in an error.Note that
Hashalso implementsFromStr, soHash::from_hex("...")is equivalent to"...".parse().
Trait Implementations
impl Clone for Hash
fn clone(&self) -> Self
impl Copy for Hash
impl Debug for Hash
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Display for Hash
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Eq for Hash
impl From<[u8; 32]> for Hash
fn from(bytes: [u8; 32]) -> Self
impl FromStr for Hash
type Err = HexError;fn from_str(s: &str) -> Result<Self, Self::Err>
impl Hash for Hash
fn hash<__H: Hasher>(&self, state: &mut __H)
impl PartialEq for Hash
fn eq(&self, other: &Hash) -> bool
impl PartialEq<[u8; 32]> for Hash
fn eq(&self, other: &[u8; 32]) -> bool
impl PartialEq<[u8]> for Hash
fn eq(&self, other: &[u8]) -> bool
Auto Trait Implementations
impl Freeze for Hash
impl RefUnwindSafe for Hash
impl Send for Hash
impl Sync for Hash
impl Unpin for Hash
impl UnsafeUnpin for Hash
impl UnwindSafe for Hash
Blanket Implementations
impl<T> Any for Hash
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Hash
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Hash
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for Hash
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for Hash
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for Hash
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T> ToString for Hash
where
T: Display + ?Sized,
fn to_string(&self) -> String
impl<T, U> Into<U> for Hash
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for Hash
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for Hash
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>