pub trait Hash: Copy + Clone + PartialEq<Self> + Eq + PartialOrd<Self> + Ord + Hash + Debug + Display + LowerHex + Index<RangeFull, Output = [u8], Output = [u8], Output = [u8], Output = [u8], Output = u8> + Index<RangeFrom<usize>> + Index<RangeTo<usize>> + Index<Range<usize>> + Index<usize> + Borrow<[u8]> {
type Engine: HashEngine;
type Bytes: FromHex + Copy;
const LEN: usize;
const DISPLAY_BACKWARD: bool = false;
// Required methods
fn from_engine(e: Self::Engine) -> Self;
fn from_slice(sl: &[u8]) -> Result<Self, FromSliceError>;
fn to_byte_array(self) -> Self::Bytes;
fn as_byte_array(&self) -> &Self::Bytes;
fn from_byte_array(bytes: Self::Bytes) -> Self;
fn all_zeros() -> Self;
// Provided methods
fn engine() -> Self::Engine { ... }
fn hash(data: &[u8]) -> Self { ... }
fn hash_byte_chunks<B, I>(byte_slices: I) -> Self
where B: AsRef<[u8]>,
I: IntoIterator<Item = B> { ... }
}
Expand description
Trait which applies to hashes of all types.
Required Associated Types§
sourcetype Engine: HashEngine
type Engine: HashEngine
A hashing engine which bytes can be serialized into. It is expected
to implement the io::Write
trait, and to never return errors under
any conditions.
Required Associated Constants§
Provided Associated Constants§
sourceconst DISPLAY_BACKWARD: bool = false
const DISPLAY_BACKWARD: bool = false
Flag indicating whether user-visible serializations of this hash
should be backward. For some reason Satoshi decided this should be
true for Sha256dHash
, so here we are.
Required Methods§
sourcefn from_engine(e: Self::Engine) -> Self
fn from_engine(e: Self::Engine) -> Self
Produces a hash from the current state of a given engine.
sourcefn from_slice(sl: &[u8]) -> Result<Self, FromSliceError>
fn from_slice(sl: &[u8]) -> Result<Self, FromSliceError>
Copies a byte slice into a hash object.
sourcefn to_byte_array(self) -> Self::Bytes
fn to_byte_array(self) -> Self::Bytes
Returns the underlying byte array.
sourcefn as_byte_array(&self) -> &Self::Bytes
fn as_byte_array(&self) -> &Self::Bytes
Returns a reference to the underlying byte array.
sourcefn from_byte_array(bytes: Self::Bytes) -> Self
fn from_byte_array(bytes: Self::Bytes) -> Self
Constructs a hash from the underlying byte array.
Provided Methods§
sourcefn hash_byte_chunks<B, I>(byte_slices: I) -> Selfwhere
B: AsRef<[u8]>,
I: IntoIterator<Item = B>,
fn hash_byte_chunks<B, I>(byte_slices: I) -> Selfwhere B: AsRef<[u8]>, I: IntoIterator<Item = B>,
Hashes all the byte slices retrieved from the iterator together.