I'm trying to Sha256
hash a struct to generate a GUID for that struct based on its contents.
use sha2::{Digest, Sha256};
use std::hash::{Hash, Hasher};
#[derive(Hash)]
struct Person {
firstName: String;
lastName: String;
}
let a = Person {
firstName: "bob".to_string(),
lastName: "the builder".to_string()
}
let mut s = Sha256::new();
a.hash(&mut s);
println!("{}", s.finsih());
My stretch goal would be to simply use a.id()
which would hash all the properties on that struct. Is this a impl Person { id() -> String }
?
I tried using impl x for y
but that threw a impl doesn't use types inside crate
impl Hasher for Sha256 {
fn finish(&self) -> u64 {
self.0.result()
}
fn write(&mut self, msg: &[u8]) {
self.0.input(msg)
}
}