Implement the Write trait ?
Hi,
I've used seahash in the past, and yesterday I was reading this and I thought it would be "neat" to also have the Write trait implemented for the SeaHasher
.
I'm copying the example I linked:
use seahash::SeaHasher;
use std::{fs, io};
let mut file = fs::File::open(&path)?;
let mut hasher = SeaHasher::new();
let n = io::copy(&mut file, &mut hasher)?;
let hash = hasher.finish();
I think it would require very little additional code to do:
use core::hash::Hasher;
#[cfg(feature = "std")]
impl std::io::Write for SeaHasher {
fn write(&mut self, buf: &[u8]) -> st::io::Result<usize> {
Hasher::write(self, buf);
Ok(buf.len())
}
fn flush(&mut self) -> std::io::Result<()> {
Ok(())
}
}
Just an idea. But when I wanted to hash a whole file I ended writing almost the same code as the canonical io::copy
. It can be placed behind an "std" feature flag.
Edited by jRimbault