1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#![cfg_attr(feature = "default", doc = include_str!("../README.md"))]
#![forbid(unsafe_code)]

#[cfg(not(any(feature = "fnv")))]
compile_error!("At least one of the features `fnv` must be enabled.");

#[cfg(feature = "fnv")]
mod fnv;

#[cfg(feature = "fnv")]
pub use fnv::Fnv;

#[cfg(test)]
mod tests {
    use std::panic::{RefUnwindSafe, UnwindSafe};

    use digest::Digest;
    use hex::ToHex;

    pub fn hash<T: Digest + Clone + UnwindSafe + RefUnwindSafe + 'static>(
        data: impl AsRef<[u8]>,
    ) -> String {
        let mut hasher = T::new();
        hasher.update(data);
        hasher.finalize().to_vec().encode_hex_upper()
    }
}