[−][src]Trait merkletree::hash::Hashable
A hashable type.
Types implementing Hashable
are able to be [hash
]ed with an instance of
Hasher
.
Implementing Hashable
You can derive Hashable
with #[derive(Hashable)]
if all fields implement Hashable
.
The resulting hash will be the combination of the values from calling
[hash
] on each field.
#[macro_use]
extern crate merkletree_derive;
extern crate merkletree;
use merkletree::hash::Hashable;
fn main() {
#[derive(Hashable)]
struct Foo {
name: String,
country: String,
}
}
If you need more control over how a value is hashed, you can of course
implement the Hashable
trait yourself:
extern crate merkletree; use merkletree::hash::Hashable; use std::hash::Hasher; use std::collections::hash_map::DefaultHasher; fn main() { struct Person { id: u32, name: String, phone: u64, } impl<H: Hasher> Hashable<H> for Person { fn hash(&self, state: &mut H) { self.id.hash(state); self.name.hash(state); self.phone.hash(state); } } let foo = Person{ id: 1, name: String::from("blah"), phone: 2, }; let mut hr = DefaultHasher::new(); foo.hash(&mut hr); assert_eq!(hr.finish(), 7101638158313343130) }
Hashable
and Eq
When implementing both Hashable
and Eq
, it is important that the following
property holds:
k1 == k2 -> hash(k1) == hash(k2)
In other words, if two keys are equal, their hashes must also be equal.
Required methods
Loading content...Provided methods
fn hash_slice(data: &[Self], state: &mut H) where
Self: Sized,
Self: Sized,
Feeds a slice of this type into the given Hasher
.
Implementations on Foreign Types
impl<H: Hasher> Hashable<H> for u8
[src]
impl<H: Hasher> Hashable<H> for u16
[src]
impl<H: Hasher> Hashable<H> for u32
[src]
impl<H: Hasher> Hashable<H> for u64
[src]
impl<H: Hasher> Hashable<H> for usize
[src]
impl<H: Hasher> Hashable<H> for i8
[src]
impl<H: Hasher> Hashable<H> for i16
[src]
impl<H: Hasher> Hashable<H> for i32
[src]
impl<H: Hasher> Hashable<H> for i64
[src]
impl<H: Hasher> Hashable<H> for isize
[src]
impl<H: Hasher> Hashable<H> for [u8; 1]
[src]
impl<H: Hasher> Hashable<H> for [u8; 2]
[src]
impl<H: Hasher> Hashable<H> for [u8; 3]
[src]
impl<H: Hasher> Hashable<H> for [u8; 4]
[src]
impl<H: Hasher> Hashable<H> for [u8; 5]
[src]
impl<H: Hasher> Hashable<H> for [u8; 6]
[src]
impl<H: Hasher> Hashable<H> for [u8; 7]
[src]
impl<H: Hasher> Hashable<H> for [u8; 8]
[src]
impl<H: Hasher> Hashable<H> for [u8; 9]
[src]
impl<H: Hasher> Hashable<H> for [u8; 10]
[src]
impl<H: Hasher> Hashable<H> for [u8; 11]
[src]
impl<H: Hasher> Hashable<H> for [u8; 12]
[src]
impl<H: Hasher> Hashable<H> for [u8; 13]
[src]
impl<H: Hasher> Hashable<H> for [u8; 14]
[src]
impl<H: Hasher> Hashable<H> for [u8; 15]
[src]
impl<H: Hasher> Hashable<H> for [u8; 16]
[src]
impl<H: Hasher> Hashable<H> for [u8; 17]
[src]
impl<H: Hasher> Hashable<H> for [u8; 18]
[src]
impl<H: Hasher> Hashable<H> for [u8; 19]
[src]
impl<H: Hasher> Hashable<H> for [u8; 20]
[src]
impl<H: Hasher> Hashable<H> for [u8; 21]
[src]
impl<H: Hasher> Hashable<H> for [u8; 22]
[src]
impl<H: Hasher> Hashable<H> for [u8; 23]
[src]
impl<H: Hasher> Hashable<H> for [u8; 24]
[src]
impl<H: Hasher> Hashable<H> for [u8; 25]
[src]
impl<H: Hasher> Hashable<H> for [u8; 26]
[src]
impl<H: Hasher> Hashable<H> for [u8; 27]
[src]
impl<H: Hasher> Hashable<H> for [u8; 28]
[src]
impl<H: Hasher> Hashable<H> for [u8; 29]
[src]
impl<H: Hasher> Hashable<H> for [u8; 30]
[src]
impl<H: Hasher> Hashable<H> for [u8; 31]
[src]
impl<H: Hasher> Hashable<H> for [u8; 32]
[src]
impl<H: Hasher> Hashable<H> for [u8; 33]
[src]
impl<H: Hasher> Hashable<H> for [u8; 34]
[src]
impl<H: Hasher> Hashable<H> for [u8; 35]
[src]
impl<H: Hasher> Hashable<H> for [u8; 36]
[src]
impl<H: Hasher> Hashable<H> for [u8; 37]
[src]
impl<H: Hasher> Hashable<H> for [u8; 38]
[src]
impl<H: Hasher> Hashable<H> for [u8; 39]
[src]
impl<H: Hasher> Hashable<H> for [u8; 40]
[src]
impl<H: Hasher> Hashable<H> for [u8; 41]
[src]
impl<H: Hasher> Hashable<H> for [u8; 42]
[src]
impl<H: Hasher> Hashable<H> for [u8; 43]
[src]
impl<H: Hasher> Hashable<H> for [u8; 44]
[src]
impl<H: Hasher> Hashable<H> for [u8; 45]
[src]
impl<H: Hasher> Hashable<H> for [u8; 46]
[src]
impl<H: Hasher> Hashable<H> for [u8; 47]
[src]
impl<H: Hasher> Hashable<H> for [u8; 48]
[src]
impl<H: Hasher> Hashable<H> for [u8; 49]
[src]
impl<H: Hasher> Hashable<H> for [u8; 50]
[src]
impl<H: Hasher> Hashable<H> for [u8; 51]
[src]
impl<H: Hasher> Hashable<H> for [u8; 52]
[src]
impl<H: Hasher> Hashable<H> for [u8; 53]
[src]
impl<H: Hasher> Hashable<H> for [u8; 54]
[src]
impl<H: Hasher> Hashable<H> for [u8; 55]
[src]
impl<H: Hasher> Hashable<H> for [u8; 56]
[src]
impl<H: Hasher> Hashable<H> for [u8; 57]
[src]
impl<H: Hasher> Hashable<H> for [u8; 58]
[src]
impl<H: Hasher> Hashable<H> for [u8; 59]
[src]
impl<H: Hasher> Hashable<H> for [u8; 60]
[src]
impl<H: Hasher> Hashable<H> for [u8; 61]
[src]
impl<H: Hasher> Hashable<H> for [u8; 62]
[src]
impl<H: Hasher> Hashable<H> for [u8; 63]
[src]
impl<H: Hasher> Hashable<H> for [u8; 64]
[src]
impl<H: Hasher> Hashable<H> for Vec<u8>
[src]
impl<H: Hasher> Hashable<H> for bool
[src]
impl<H: Hasher> Hashable<H> for char
[src]
impl<H: Hasher> Hashable<H> for str
[src]
impl<H: Hasher> Hashable<H> for String
[src]
impl<H: Hasher> Hashable<H> for ()
[src]
impl<Z: Hasher, A> Hashable<Z> for (A,) where
A: Hashable<Z> + ?Sized,
[src]
A: Hashable<Z> + ?Sized,
impl<Z: Hasher, A: Hashable<Z>, B> Hashable<Z> for (A, B) where
B: Hashable<Z> + ?Sized,
[src]
B: Hashable<Z> + ?Sized,
impl<Z: Hasher, A: Hashable<Z>, B: Hashable<Z>, C> Hashable<Z> for (A, B, C) where
C: Hashable<Z> + ?Sized,
[src]
C: Hashable<Z> + ?Sized,
impl<Z: Hasher, A: Hashable<Z>, B: Hashable<Z>, C: Hashable<Z>, D> Hashable<Z> for (A, B, C, D) where
D: Hashable<Z> + ?Sized,
[src]
D: Hashable<Z> + ?Sized,
impl<Z: Hasher, A: Hashable<Z>, B: Hashable<Z>, C: Hashable<Z>, D: Hashable<Z>, E> Hashable<Z> for (A, B, C, D, E) where
E: Hashable<Z> + ?Sized,
[src]
E: Hashable<Z> + ?Sized,
impl<Z: Hasher, A: Hashable<Z>, B: Hashable<Z>, C: Hashable<Z>, D: Hashable<Z>, E: Hashable<Z>, F> Hashable<Z> for (A, B, C, D, E, F) where
F: Hashable<Z> + ?Sized,
[src]
F: Hashable<Z> + ?Sized,
impl<Z: Hasher, A: Hashable<Z>, B: Hashable<Z>, C: Hashable<Z>, D: Hashable<Z>, E: Hashable<Z>, F: Hashable<Z>, G> Hashable<Z> for (A, B, C, D, E, F, G) where
G: Hashable<Z> + ?Sized,
[src]
G: Hashable<Z> + ?Sized,
impl<Z: Hasher, A: Hashable<Z>, B: Hashable<Z>, C: Hashable<Z>, D: Hashable<Z>, E: Hashable<Z>, F: Hashable<Z>, G: Hashable<Z>, H> Hashable<Z> for (A, B, C, D, E, F, G, H) where
H: Hashable<Z> + ?Sized,
[src]
H: Hashable<Z> + ?Sized,
impl<Z: Hasher, A: Hashable<Z>, B: Hashable<Z>, C: Hashable<Z>, D: Hashable<Z>, E: Hashable<Z>, F: Hashable<Z>, G: Hashable<Z>, H: Hashable<Z>, I> Hashable<Z> for (A, B, C, D, E, F, G, H, I) where
I: Hashable<Z> + ?Sized,
[src]
I: Hashable<Z> + ?Sized,
impl<Z: Hasher, A: Hashable<Z>, B: Hashable<Z>, C: Hashable<Z>, D: Hashable<Z>, E: Hashable<Z>, F: Hashable<Z>, G: Hashable<Z>, H: Hashable<Z>, I: Hashable<Z>, J> Hashable<Z> for (A, B, C, D, E, F, G, H, I, J) where
J: Hashable<Z> + ?Sized,
[src]
J: Hashable<Z> + ?Sized,
impl<Z: Hasher, A: Hashable<Z>, B: Hashable<Z>, C: Hashable<Z>, D: Hashable<Z>, E: Hashable<Z>, F: Hashable<Z>, G: Hashable<Z>, H: Hashable<Z>, I: Hashable<Z>, J: Hashable<Z>, K> Hashable<Z> for (A, B, C, D, E, F, G, H, I, J, K) where
K: Hashable<Z> + ?Sized,
[src]
K: Hashable<Z> + ?Sized,
impl<Z: Hasher, A: Hashable<Z>, B: Hashable<Z>, C: Hashable<Z>, D: Hashable<Z>, E: Hashable<Z>, F: Hashable<Z>, G: Hashable<Z>, H: Hashable<Z>, I: Hashable<Z>, J: Hashable<Z>, K: Hashable<Z>, L> Hashable<Z> for (A, B, C, D, E, F, G, H, I, J, K, L) where
L: Hashable<Z> + ?Sized,
[src]
L: Hashable<Z> + ?Sized,