Skip to main content

omega_cache/core/
utils.rs

1#[cfg(test)]
2use rand::distr::{Alphanumeric, SampleString};
3#[cfg(test)]
4use rand::{RngExt, rng};
5use std::hash::{Hash, Hasher};
6use twox_hash::xxhash64::Hasher as XxHash64;
7
8#[inline(always)]
9pub fn hash<T: Eq + Hash>(value: T) -> u64 {
10    let mut hasher = XxHash64::default();
11    value.hash(&mut hasher);
12    hasher.finish()
13}
14
15#[cfg(test)]
16#[inline(always)]
17pub fn random_string_with_len(len: usize) -> String {
18    Alphanumeric.sample_string(&mut rand::rng(), len)
19}
20
21#[cfg(test)]
22#[inline(always)]
23pub fn random_string() -> String {
24    let len = rng().random_range(10..255);
25    random_string_with_len(len)
26}