Struct diem_sdk::crypto::HashValue [−][src]
pub struct HashValue { /* fields omitted */ }
Expand description
Output value of our hash function. Intentionally opaque for safety and modularity.
Implementations
The length of the hash in bits.
Create from a slice (e.g. retrieved from storage).
Creates a random instance with given rng. Useful in unit tests.
Convenience function that computes a HashValue
internally equal to
the sha3_256 of a byte buffer. It will handle hasher creation, data
feeding and finalization.
Note this will not result in the <T as CryptoHash>::hash()
for any
reasonable struct T, as this computes a sha3 without any ornaments.
pub fn iter_bits(&self) -> HashValueBitIterator<'_>ⓘNotable traits for HashValueBitIterator<'a>impl<'a> Iterator for HashValueBitIterator<'a> type Item = bool;
pub fn iter_bits(&self) -> HashValueBitIterator<'_>ⓘNotable traits for HashValueBitIterator<'a>impl<'a> Iterator for HashValueBitIterator<'a> type Item = bool;
impl<'a> Iterator for HashValueBitIterator<'a> type Item = bool;
Returns a HashValueBitIterator
over all the bits that represent this HashValue
.
pub fn from_bit_iter(
iter: impl ExactSizeIterator<Item = bool>
) -> Result<HashValue, HashValueParseError>
pub fn from_bit_iter(
iter: impl ExactSizeIterator<Item = bool>
) -> Result<HashValue, HashValueParseError>
Constructs a HashValue
from an iterator of bits.
Returns the length of common prefix of self
and other
in bits.
Full hex representation of a given hash value with 0x
prefix.
Methods from Deref<Target = [u8; 32]>
🔬 This is a nightly-only experimental API. (array_methods
)
array_methods
)Returns a slice containing the entire array. Equivalent to &s[..]
.
🔬 This is a nightly-only experimental API. (array_methods
)
array_methods
)Borrows each element and returns an array of references with the same
size as self
.
Example
#![feature(array_methods)]
let floats = [3.1, 2.7, -1.0];
let float_refs: [&f64; 3] = floats.each_ref();
assert_eq!(float_refs, [&3.1, &2.7, &-1.0]);
This method is particularly useful if combined with other methods, like
map
. This way, you can avoid moving the original
array if its elements are not Copy
.
#![feature(array_methods)]
let strings = ["Ferris".to_string(), "♥".to_string(), "Rust".to_string()];
let is_ascii = strings.each_ref().map(|s| s.is_ascii());
assert_eq!(is_ascii, [true, false, true]);
// We can still access the original array: it has not been moved.
assert_eq!(strings.len(), 3);
Trait Implementations
pub fn deserialize<D>(
deserializer: D
) -> Result<HashValue, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
pub fn deserialize<D>(
deserializer: D
) -> Result<HashValue, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Will print shortened (4 bytes) hash
type Err = HashValueParseError
type Err = HashValueParseError
The associated error which can be returned from parsing.
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
pub fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
pub fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
Serialize this value into the given Serde serializer. Read more
Auto Trait Implementations
impl RefUnwindSafe for HashValue
impl UnwindSafe for HashValue
Blanket Implementations
Mutably borrows from an owned value. Read more
Compare self to key
and return true
if they are equal.
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
Generates a hash used only for tests.
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more