Coverage Report

Created: 2026-09-06 07:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/hashbrown-0.16.1/src/hasher.rs
Line
Count
Source
1
#[cfg(feature = "default-hasher")]
2
use {
3
    core::hash::{BuildHasher, Hasher},
4
    foldhash::fast::RandomState,
5
};
6
7
/// Default hash builder for the `S` type parameter of
8
/// [`HashMap`](crate::HashMap) and [`HashSet`](crate::HashSet).
9
///
10
/// This only implements `BuildHasher` when the "default-hasher" crate feature
11
/// is enabled; otherwise it just serves as a placeholder, and a custom `S` type
12
/// must be used to have a fully functional `HashMap` or `HashSet`.
13
#[derive(Clone, Debug, Default)]
14
pub struct DefaultHashBuilder {
15
    #[cfg(feature = "default-hasher")]
16
    inner: RandomState,
17
}
18
19
#[cfg(feature = "default-hasher")]
20
impl BuildHasher for DefaultHashBuilder {
21
    type Hasher = DefaultHasher;
22
23
    #[inline(always)]
24
2.82M
    fn build_hasher(&self) -> Self::Hasher {
25
2.82M
        DefaultHasher {
26
2.82M
            inner: self.inner.build_hasher(),
27
2.82M
        }
28
2.82M
    }
29
}
30
31
/// Default hasher for [`HashMap`](crate::HashMap) and [`HashSet`](crate::HashSet).
32
#[cfg(feature = "default-hasher")]
33
#[derive(Clone)]
34
pub struct DefaultHasher {
35
    inner: <RandomState as BuildHasher>::Hasher,
36
}
37
38
#[cfg(feature = "default-hasher")]
39
macro_rules! forward_writes {
40
    ($( $write:ident ( $ty:ty ) , )*) => {$(
41
        #[inline(always)]
42
5.94M
        fn $write(&mut self, arg: $ty) {
43
5.94M
            self.inner.$write(arg);
44
5.94M
        }
<hashbrown::hasher::DefaultHasher as core::hash::Hasher>::write_usize
Line
Count
Source
42
591k
        fn $write(&mut self, arg: $ty) {
43
591k
            self.inner.$write(arg);
44
591k
        }
<hashbrown::hasher::DefaultHasher as core::hash::Hasher>::write
Line
Count
Source
42
591k
        fn $write(&mut self, arg: $ty) {
43
591k
            self.inner.$write(arg);
44
591k
        }
<hashbrown::hasher::DefaultHasher as core::hash::Hasher>::write_u32
Line
Count
Source
42
3.11M
        fn $write(&mut self, arg: $ty) {
43
3.11M
            self.inner.$write(arg);
44
3.11M
        }
<hashbrown::hasher::DefaultHasher as core::hash::Hasher>::write_u64
Line
Count
Source
42
1.65M
        fn $write(&mut self, arg: $ty) {
43
1.65M
            self.inner.$write(arg);
44
1.65M
        }
45
    )*}
46
}
47
48
#[cfg(feature = "default-hasher")]
49
impl Hasher for DefaultHasher {
50
    forward_writes! {
51
        write(&[u8]),
52
        write_u8(u8),
53
        write_u16(u16),
54
        write_u32(u32),
55
        write_u64(u64),
56
        write_u128(u128),
57
        write_usize(usize),
58
        write_i8(i8),
59
        write_i16(i16),
60
        write_i32(i32),
61
        write_i64(i64),
62
        write_i128(i128),
63
        write_isize(isize),
64
    }
65
66
    // feature(hasher_prefixfree_extras)
67
    #[cfg(feature = "nightly")]
68
    forward_writes! {
69
        write_length_prefix(usize),
70
        write_str(&str),
71
    }
72
73
    #[inline(always)]
74
2.82M
    fn finish(&self) -> u64 {
75
2.82M
        self.inner.finish()
76
2.82M
    }
77
}