Struct diem_crypto::hash::HashValue [−][src]
Output value of our hash function. Intentionally opaque for safety and modularity.
Implementations
impl HashValue
[src]
pub const LENGTH: usize
[src]
The length of the hash in bytes.
pub const LENGTH_IN_BITS: usize
[src]
The length of the hash in bits.
pub fn new(hash: [u8; 32]) -> Self
[src]
Create a new HashValue
from a byte array.
pub fn from_slice(src: &[u8]) -> Result<Self>
[src]
Create from a slice (e.g. retrieved from storage).
pub fn to_vec(&self) -> Vec<u8>
[src]
Dumps into a vector.
pub const fn zero() -> Self
[src]
Creates a zero-initialized instance.
pub fn random() -> Self
[src]
Create a cryptographically random instance.
pub fn random_with_rng<R: Rng>(rng: &mut R) -> Self
[src]
Creates a random instance with given rng. Useful in unit tests.
pub fn sha3_256_of(buffer: &[u8]) -> Self
[src]
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;
[src]
Notable traits for HashValueBitIterator<'a>
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<Self>
[src]
Constructs a HashValue
from an iterator of bits.
pub fn common_prefix_bits_len(&self, other: HashValue) -> usize
[src]
Returns the length of common prefix of self
and other
in bits.
pub fn to_hex(&self) -> String
[src]
Full hex representation of a given hash value.
pub fn from_hex(hex_str: &str) -> Result<Self>
[src]
Parse a given hex string to a hash value.
Methods from Deref<Target = [u8; 32]>
pub fn as_slice(&self) -> &[T]
[src]
array_methods
)Returns a slice containing the entire array. Equivalent to &s[..]
.
pub fn each_ref(&self) -> [&T; N]
[src]
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 can avoid moving the original
array if its elements are not Copy
.
#![feature(array_methods, array_map)] 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
impl AsRef<[u8; 32]> for HashValue
[src]
impl Binary for HashValue
[src]
impl Clone for HashValue
[src]
impl Copy for HashValue
[src]
impl Debug for HashValue
[src]
impl Default for HashValue
[src]
impl Deref for HashValue
[src]
impl<'de> Deserialize<'de> for HashValue
[src]
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
[src]
D: Deserializer<'de>,
impl Display for HashValue
[src]
Will print shortened (4 bytes) hash
impl Eq for HashValue
[src]
impl FromStr for HashValue
[src]
type Err = Error
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Self>
[src]
impl Hash for HashValue
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Index<usize> for HashValue
[src]
impl LowerHex for HashValue
[src]
impl Ord for HashValue
[src]
fn cmp(&self, other: &HashValue) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl PartialEq<HashValue> for HashValue
[src]
impl PartialOrd<HashValue> for HashValue
[src]
fn partial_cmp(&self, other: &HashValue) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl Serialize for HashValue
[src]
impl StructuralEq for HashValue
[src]
impl StructuralPartialEq for HashValue
[src]
Auto Trait Implementations
impl RefUnwindSafe for HashValue
impl Send for HashValue
impl Sync for HashValue
impl Unpin for HashValue
impl UnwindSafe for HashValue
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> TestOnlyHash for T where
T: Serialize + ?Sized,
[src]
T: Serialize + ?Sized,
pub fn test_only_hash(&Self) -> HashValue
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,