1#![cfg_attr(feature = "default", doc = include_str!("../README.md"))]
2#![forbid(unsafe_code)]
3
4#[cfg(not(any(
5 feature = "fnv",
6 feature = "xxh3",
7 feature = "xxh32",
8 feature = "xxh64"
9)))]
10compile_error!("At least one of these features must be enabled: fnv, xxh3, xxh32, xxh64");
11
12mod common;
13pub use crate::common::HashWrapper;
14
15#[cfg(feature = "fnv")]
16mod fnv;
17#[cfg(feature = "fnv")]
18pub use crate::fnv::{Fnv, FnvHasher};
19
20#[cfg(feature = "xxh3")]
21mod xxh3;
22#[cfg(feature = "xxh3")]
23pub use crate::xxh3::{Xxh3Hasher, Xxh3_128, Xxh3_64};
24
25#[cfg(feature = "xxh32")]
26mod xxh32;
27#[cfg(feature = "xxh32")]
28pub use crate::xxh32::{Xxh32, Xxh32Hasher};
29
30#[cfg(feature = "xxh64")]
31mod xxh64;
32#[cfg(feature = "xxh64")]
33pub use crate::xxh64::{Xxh64, Xxh64Hasher};
34
35#[cfg(test)]
36mod tests {
37 use std::panic::{RefUnwindSafe, UnwindSafe};
38
39 use digest::Digest;
40 use hex::ToHex;
41
42 pub fn hash<T: Digest + Clone + UnwindSafe + RefUnwindSafe + 'static>(
43 data: impl AsRef<[u8]>,
44 ) -> String {
45 let mut hasher = T::new();
46 hasher.update(data);
47 hasher.finalize().to_vec().encode_hex_upper()
48 }
49}