pub trait Fnv{
const PRIME: Self;
const OFFSET_BASIS: Self;
// Provided methods
fn fnv1<I>(self, data: I) -> Self
where I: IntoIterator<Item = u8> { ... }
fn fnv1a<I>(self, data: I) -> Self
where I: IntoIterator<Item = u8> { ... }
}
Expand description
Fowler-Noll-Vo Hashes
Both FNV-1 and FNV-1a are provided.
Note that:
- FNV is not a cryptographic hash.
- FNV is not resistant to “hash flooding” denial-of-service attacks.
Required Associated Constants§
Sourceconst OFFSET_BASIS: Self
const OFFSET_BASIS: Self
The FNV offset basis
Provided Methods§
Sourcefn fnv1<I>(self, data: I) -> Selfwhere
I: IntoIterator<Item = u8>,
fn fnv1<I>(self, data: I) -> Selfwhere
I: IntoIterator<Item = u8>,
Compute the Fowler-Noll-Vo hash FNV-1 (multiply before xor)
Sourcefn fnv1a<I>(self, data: I) -> Selfwhere
I: IntoIterator<Item = u8>,
fn fnv1a<I>(self, data: I) -> Selfwhere
I: IntoIterator<Item = u8>,
Compute the Fowler-Noll-Vo hash FNV-1a (xor before multiply)
use yafnv::Fnv;
// Test vectors from
// https://datatracker.ietf.org/doc/draft-eastlake-fnv/21/
for (data, h32, h64) in [
("", 0x811c9dc5, 0xcbf29ce484222325),
("a", 0xe40c292c, 0xaf63dc4c8601ec8c),
("foobar", 0xbf9cf968, 0x85944171f73967e8),
] {
let data = data.as_bytes().iter().copied();
assert_eq!(u32::OFFSET_BASIS.fnv1a(data.clone()), h32);
assert_eq!(u64::OFFSET_BASIS.fnv1a(data), h64);
}
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.