I was attempting to use twox-hash to generate a hash for a file, as it seemed to be the fastest hash implementation around and security is not a concern for this implementation.
To get it to work with a reader, I implemented a wrapper struct that implemented the Write
trait and directly called XxHash::write
from the Hash
trait. Is there a more elegant or standard way of doing this?
#[derive(Deref)]
struct HashWriter<T: Hasher>(T);
impl<T: Hasher> std::io::Write for HashWriter<T> {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
self.0.write(buf);
Ok(buf.len())
}
fn flush(&mut self) -> std::io::Result<()> {
Ok(())
}
}