summaryrefslogtreecommitdiff
path: root/src/util/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/mod.rs')
-rw-r--r--src/util/mod.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/util/mod.rs b/src/util/mod.rs
index bc7aa250..df3c446e 100644
--- a/src/util/mod.rs
+++ b/src/util/mod.rs
@@ -3,7 +3,7 @@
pub mod fat;
pub use buffer::Buffer;
-pub use eco::EcoString;
+pub use eco::{format_eco, EcoString};
#[macro_use]
mod eco;
@@ -11,9 +11,12 @@ mod buffer;
use std::any::TypeId;
use std::fmt::{self, Debug, Formatter};
+use std::hash::Hash;
use std::path::{Component, Path, PathBuf};
use std::sync::Arc;
+use siphasher::sip128::{Hasher128, SipHasher};
+
/// Turn a closure into a struct implementing [`Debug`].
pub fn debug<F>(f: F) -> impl Debug
where
@@ -33,6 +36,13 @@ where
Wrapper(f)
}
+/// Calculate a 128-bit siphash of a value.
+pub fn hash128<T: Hash>(value: &T) -> u128 {
+ let mut state = SipHasher::new();
+ value.hash(&mut state);
+ state.finish128().as_u128()
+}
+
/// Extra methods for [`str`].
pub trait StrExt {
/// The number of code units this string would use if it was encoded in