pub struct Blockhash256(/* private fields */);Expand description
A 256-bit hash digest.
See blockhash256.
Implementations§
Source§impl Blockhash256
impl Blockhash256
Sourcepub fn distance(&self, other: &Self) -> u32
pub fn distance(&self, other: &Self) -> u32
Returns the Hamming distance between two hashes.
§Examples
use blockhash::Blockhash256;
let a = Blockhash256::from([
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
0xff, 0xef, 0xdf, 0xcf, 0xbf, 0xaf, 0x9f, 0x8f,
0x7f, 0x6f, 0x5f, 0x4f, 0x3f, 0x2f, 0x1f, 0x0f,
]);
let b = Blockhash256::from([
0x00, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
0xf8, 0xf9, 0x3a, 0xfb, 0xfc, 0xfd, 0x0e, 0xff,
0xff, 0xff, 0xdf, 0xcf, 0xbf, 0xaf, 0x9f, 0x8f,
0x7f, 0x6f, 0x5f, 0x4f, 0x3f, 0x2f, 0x1f, 0x0f,
]);
assert_eq!(a.distance(&b), 11);Trait Implementations§
Source§impl Clone for Blockhash256
impl Clone for Blockhash256
Source§fn clone(&self) -> Blockhash256
fn clone(&self) -> Blockhash256
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for Blockhash256
impl Debug for Blockhash256
Source§impl Display for Blockhash256
impl Display for Blockhash256
Source§impl From<Blockhash256> for [u8; 32]
impl From<Blockhash256> for [u8; 32]
Source§fn from(hash: Blockhash256) -> Self
fn from(hash: Blockhash256) -> Self
Converts to this type from the input type.
Source§impl FromStr for Blockhash256
impl FromStr for Blockhash256
Source§impl Hash for Blockhash256
impl Hash for Blockhash256
Source§impl Ord for Blockhash256
impl Ord for Blockhash256
Source§fn cmp(&self, other: &Blockhash256) -> Ordering
fn cmp(&self, other: &Blockhash256) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for Blockhash256
impl PartialEq for Blockhash256
Source§impl PartialOrd for Blockhash256
impl PartialOrd for Blockhash256
impl Copy for Blockhash256
impl Eq for Blockhash256
impl StructuralPartialEq for Blockhash256
Auto Trait Implementations§
impl Freeze for Blockhash256
impl RefUnwindSafe for Blockhash256
impl Send for Blockhash256
impl Sync for Blockhash256
impl Unpin for Blockhash256
impl UnwindSafe for Blockhash256
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more