diff --git a/dynatos-util/src/lib.rs b/dynatos-util/src/lib.rs index b50491c..8162419 100644 --- a/dynatos-util/src/lib.rs +++ b/dynatos-util/src/lib.rs @@ -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: &T) -> u64 { + let mut s = hash::DefaultHasher::new(); + t.hash(&mut s); + s.finish() +}