use decanter::hash::{hasher, Hashable, H256};
fn main() {
let sample = Sample::new("Hello, world!".to_string());
println!("Hash: {}", sample.hash());
assert_eq!(sample.hash(), H256::from(hasher("Hello, world!")));
}
#[derive(Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct Sample {
pub value: String,
}
impl Sample {
pub fn new(value: String) -> Self {
Self { value }
}
}
impl Hashable for Sample {
fn hash(&self) -> H256 {
hasher(self.to_string()).into()
}
}
impl std::fmt::Display for Sample {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.value)
}
}