Trait Hashing

Source
pub trait Hashing<const LENGTH: usize>: Clone + Sized {
    // Required methods
    fn hash(data: &[u8]) -> Self;
    fn as_bytes(&self) -> &[u8] ;
    fn from_bytes(bytes: &[u8]) -> StacksResult<Self>;

    // Provided methods
    fn new(value: impl AsRef<[u8]>) -> Self { ... }
    fn zeroes() -> Self { ... }
    fn checksum(&self) -> [u8; 4] { ... }
    fn from_hex(data: impl AsRef<str>) -> StacksResult<Self> { ... }
    fn to_hex(&self) -> String { ... }
}
Expand description

Hashing trait

Required Methods§

Source

fn hash(data: &[u8]) -> Self

Hash the given data

Source

fn as_bytes(&self) -> &[u8]

Get the bytes of the hash

Source

fn from_bytes(bytes: &[u8]) -> StacksResult<Self>

Attempt to create a hash from the given bytes

Provided Methods§

Source

fn new(value: impl AsRef<[u8]>) -> Self

Create a hash from the given bytes

Source

fn zeroes() -> Self

Create a zeroed hash

Source

fn checksum(&self) -> [u8; 4]

Get the checksum of the hash

Source

fn from_hex(data: impl AsRef<str>) -> StacksResult<Self>

Attempt to create a hash from the given hex bytes

Source

fn to_hex(&self) -> String

Get the hex representation of the hash

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Hashing<HASH160_LENGTH> for Hash160Hashing

Source§

impl Hashing<SHA256_LENGTH> for DoubleSha256Hashing

Source§

impl Hashing<SHA256_LENGTH> for Sha256Hashing

Source§

impl<T, const LENGTH: usize> Hashing<LENGTH> for Hasher<T, LENGTH>
where T: Hashing<LENGTH>,