mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
style: Make PrecomputedHasher fail loudly and with error messages when used incorrectly.
This commit is contained in:
parent
720b17a54b
commit
3d54c0710f
1 changed files with 7 additions and 5 deletions
|
@ -25,12 +25,12 @@ use stylist::Rule;
|
||||||
/// A hasher implementation that doesn't hash anything, because it expects its
|
/// A hasher implementation that doesn't hash anything, because it expects its
|
||||||
/// input to be a suitable u32 hash.
|
/// input to be a suitable u32 hash.
|
||||||
pub struct PrecomputedHasher {
|
pub struct PrecomputedHasher {
|
||||||
hash: u32,
|
hash: Option<u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for PrecomputedHasher {
|
impl Default for PrecomputedHasher {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self { hash: 0 }
|
Self { hash: None }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,17 +43,19 @@ pub type PrecomputedHashSet<K> = HashSet<K, BuildHasherDefault<PrecomputedHasher
|
||||||
impl Hasher for PrecomputedHasher {
|
impl Hasher for PrecomputedHasher {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn write(&mut self, _: &[u8]) {
|
fn write(&mut self, _: &[u8]) {
|
||||||
unreachable!()
|
unreachable!("Called into PrecomputedHasher with something that isn't \
|
||||||
|
a u32")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn write_u32(&mut self, i: u32) {
|
fn write_u32(&mut self, i: u32) {
|
||||||
self.hash = i;
|
debug_assert!(self.hash.is_none());
|
||||||
|
self.hash = Some(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn finish(&self) -> u64 {
|
fn finish(&self) -> u64 {
|
||||||
self.hash as u64
|
self.hash.expect("PrecomputedHasher wasn't fed?") as u64
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue