Skip to content

Commit 95ad518

Browse files
committed
Remove nohash-hasher dependency
Signed-off-by: Liam Gray <[email protected]>
1 parent 947534e commit 95ad518

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ push = ["reqwest", "libc", "protobuf"]
2424
[dependencies]
2525
cfg-if = "^1.0"
2626
fnv = "^1.0"
27-
nohash-hasher = "0.2.0"
2827
lazy_static = "^1.4"
2928
libc = { version = "^0.2", optional = true }
3029
parking_lot = "^0.12"

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ mod errors;
158158
mod gauge;
159159
mod histogram;
160160
mod metrics;
161+
mod nohash;
161162
mod pulling_gauge;
162163
#[cfg(feature = "push")]
163164
mod push;

src/nohash.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use std::hash::{BuildHasherDefault, Hasher};
2+
3+
/// Inspired by nohash-hasher, but we avoid the crate dependency because it's in public archive.
4+
#[derive(Copy, Clone, Debug, Default)]
5+
pub struct NoHashHasher(u64);
6+
7+
pub type BuildNoHashHasher = BuildHasherDefault<NoHashHasher>;
8+
9+
impl Hasher for NoHashHasher {
10+
#[inline]
11+
fn finish(&self) -> u64 {
12+
self.0
13+
}
14+
15+
fn write(&mut self, _bytes: &[u8]) {
16+
panic!("Invalid use of NoHashHasher");
17+
}
18+
19+
#[inline]
20+
fn write_u64(&mut self, i: u64) {
21+
self.0 = i;
22+
}
23+
}

src/vec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ use std::collections::HashMap;
55
use std::hash::{BuildHasher, Hasher};
66
use std::sync::Arc;
77
use fnv::FnvHasher;
8-
use nohash_hasher::BuildNoHashHasher;
98
use parking_lot::RwLock;
109

1110
use crate::desc::{Desc, Describer};
1211
use crate::errors::{Error, Result};
1312
use crate::metrics::{Collector, Metric};
13+
use crate::nohash::BuildNoHashHasher;
1414
use crate::proto::{MetricFamily, MetricType};
1515

1616
/// An interface for building a metric vector.
@@ -27,7 +27,7 @@ pub trait MetricVecBuilder: Send + Sync + Clone {
2727
#[derive(Debug)]
2828
pub(crate) struct MetricVecCore<T: MetricVecBuilder> {
2929
// the key is pre-hashed, and so we use a no-hash hasher to avoid hashing again.
30-
pub children: RwLock<HashMap<u64, T::M, BuildNoHashHasher<u64>>>,
30+
pub children: RwLock<HashMap<u64, T::M, BuildNoHashHasher>>,
3131
pub desc: Desc,
3232
pub metric_type: MetricType,
3333
pub new_metric: T,

0 commit comments

Comments
 (0)