trait

Hasher — stateful hash computation

A Hasher accepts input and produces a numeric digest of its current state. finish does not reset that state. Hash values from the standard implementation are not portable persistent identifiers. Expected stdout (not executed): true Common mistake: Assuming a sequence of write calls is always interchangeable with one concatenated write call.

Formal Syntax & Structure

rust syntaxrust
pub trait Hasher { fn finish(&self) -> u64; fn write(&mut self, bytes: &[u8]); /* provided methods omitted */ }

Working Example

Example Snippetrust
fn main() {    use std::hash::{DefaultHasher, Hasher};    let mut h = DefaultHasher::new();    h.write(b"task");    println!("{}", h.finish() == h.finish());}
Rust Reference