pub struct Hash<T: Tag>(/* private fields */);Expand description
Output of the SHA256t hash function.
Implementations§
Source§impl<T: Tag> Hash<T>
impl<T: Tag> Hash<T>
Sourcepub fn hash(bytes: &[u8]) -> Self
pub fn hash(bytes: &[u8]) -> Self
Creates a default hash engine, adds bytes to it, then finalizes the engine.
§Returns
The digest created by hashing bytes with engine’s hashing algorithm.
Sourcepub fn from_engine(engine: Engine<T>) -> Self
pub fn from_engine(engine: Engine<T>) -> Self
Creates a Hash from an engine.
This is equivalent to calling Hash::from_byte_array(engine.finalize()).
Sourcepub fn from_bytes_ref(bytes: &[u8; 32]) -> &Self
pub fn from_bytes_ref(bytes: &[u8; 32]) -> &Self
Zero cost conversion between a fixed length byte array shared reference and a shared reference to this Hash type.
Sourcepub fn from_bytes_mut(bytes: &mut [u8; 32]) -> &mut Self
pub fn from_bytes_mut(bytes: &mut [u8; 32]) -> &mut Self
Zero cost conversion between a fixed length byte array exclusive reference and an exclusive reference to this Hash type.
Sourcepub fn from_slice(sl: &[u8]) -> Result<Self, FromSliceError>
pub fn from_slice(sl: &[u8]) -> Result<Self, FromSliceError>
Copies a byte slice into a hash object.
Sourcepub fn from_byte_array(bytes: [u8; 32]) -> Self
pub fn from_byte_array(bytes: [u8; 32]) -> Self
Constructs a hash from the underlying byte array.
Sourcepub fn to_byte_array(self) -> [u8; 32]
pub fn to_byte_array(self) -> [u8; 32]
Returns the underlying byte array.
Sourcepub fn as_byte_array(&self) -> &[u8; 32]
pub fn as_byte_array(&self) -> &[u8; 32]
Returns a reference to the underlying byte array.
Sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
Available on crate feature alloc only.
pub fn to_bytes(&self) -> Vec<u8> ⓘ
alloc only.Copies the underlying bytes into a new Vec.
Sourcepub fn all_zeros() -> Self
pub fn all_zeros() -> Self
Returns an all zero hash.
An all zeros hash is a made up construct because there is not a known input that can create it, however it is used in various places in Bitcoin e.g., the Bitcoin genesis block’s previous blockhash and the coinbase transaction’s outpoint txid.
Trait Implementations§
Source§impl<'de, T: Tag> Deserialize<'de> for Hash<T>
impl<'de, T: Tag> Deserialize<'de> for Hash<T>
Source§fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Hash<T>, D::Error>
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Hash<T>, D::Error>
Source§impl<T: Tag> JsonSchema for Hash<T>
Available on crate feature schemars only.
impl<T: Tag> JsonSchema for Hash<T>
schemars only.Source§fn schema_name() -> String
fn schema_name() -> String
Source§fn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
Source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref keyword. Read moreSource§impl<T: Tag> Ord for Hash<T>
impl<T: Tag> Ord for Hash<T>
Source§impl<T: Tag> PartialOrd for Hash<T>
impl<T: Tag> PartialOrd for Hash<T>
Source§impl<T: Tag> SerdeHash for Hash<T>
impl<T: Tag> SerdeHash for Hash<T>
Source§fn from_slice_delegated(sl: &[u8]) -> Result<Self, FromSliceError>
fn from_slice_delegated(sl: &[u8]) -> Result<Self, FromSliceError>
serde only.Source§fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error>
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error>
serde only.Source§fn deserialize<'de, D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
fn deserialize<'de, D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
serde only.