use std::borrow::Cow;
use const_hex::{traits::FromHex, FromHexError};
use ethers::types::Address;
pub mod blake3;
pub mod keccak256;
pub trait Hasher {
type Hash: FromHex<Error = FromHexError>;
fn new() -> Self;
fn update(&mut self, data: &[u8]) -> &mut Self;
fn update_mmap_rayon(&mut self, path: &std::path::Path) -> Result<(), std::io::Error>;
fn update_mmap(&mut self, path: &std::path::Path) -> Result<(), std::io::Error>;
fn finalize(self) -> Self::Hash;
}
pub trait Hashable {
fn collect(&self) -> Cow<[u8]>;
fn hash<HSH: Hasher>(&self) -> HSH::Hash {
let mut hasher = HSH::new();
hasher.update(&self.collect());
hasher.finalize()
}
}
impl Hashable for Address {
fn collect(&self) -> Cow<[u8]> {
self.as_bytes().into()
}
}