use crate::compat::*;
pub(crate) fn hash_one<H: Hash + ?Sized, S: BuildHasher>(hash_builder: &S, value: &H) -> u64 {
let mut hasher = hash_builder.build_hasher();
value.hash(&mut hasher);
hasher.finish()
}
pub(crate) fn each_ref<T, const N: usize>(array: &[T; N]) -> [&T; N] {
if N == 0 {
return vec![]
.try_into()
.map_err(|_vec| ())
.expect("Unable to construct empty array!");
}
let mut refs = [&array[0]; N];
for i in 0..N {
refs[i] = &array[i];
}
refs
}
#[cfg(test)]
mod test {
use crate::compat::sync::Arc;
use super::each_ref;
#[test]
fn check_each_ref() {
let abc = [Arc::new(1), Arc::new(2), Arc::new(3)];
let abc_ref: [&Arc<_>; 3] = each_ref(&abc);
for (x, y) in abc.iter().zip(abc_ref) {
assert!(Arc::ptr_eq(x, y));
}
let empty: [u32; 0] = [];
let _empty_ref: [&u32; 0] = each_ref(&empty);
}
}