Added dynatos_util::hash_of

This commit is contained in:
Filipe Rodrigues 2024-02-06 15:01:18 +00:00
parent 445fd1c89a
commit 58b235f55f
Signed by: zenithsiz
SSH Key Fingerprint: SHA256:Mb5ppb3Sh7IarBO/sBTXLHbYEOz37hJAlslLQPPAPaU

View File

@ -18,7 +18,10 @@ pub use self::{
// Imports
use {
js_sys::Reflect,
std::fmt,
std::{
fmt,
hash::{self, Hasher},
},
wasm_bindgen::{JsCast, JsValue},
};
@ -76,3 +79,10 @@ pub impl js_sys::Object {
value.dyn_into().map_err(GetError::WrongType)
}
}
/// Calculates the hash of a value using the default hasher
pub fn hash_of<T: hash::Hash>(t: &T) -> u64 {
let mut s = hash::DefaultHasher::new();
t.hash(&mut s);
s.finish()
}