Skip to content

Commit 97ac129

Browse files
bors[bot]japaric
andauthored
Merge #284
284: [breaking-change] use hash32 v0.3.0 r=japaric a=japaric this release of `hash32` has the advantage that 32-bit hashers can be used to hash types that implement the `core::hash::Hash` trait removing the need for the `hash32::Hash` implementations in this crate and the uses of the `#[derive(Hash32)]` macro (which did not support enums) in dependent crates with this change the following code works ``` rust // NOTE no derive(Hash32) #[derive(Hash)] struct Int(i32); let mut x = FnvIndexSet::<_, 4>::default(); let _ = x.insert(Int(0)); ``` this change is technically a breaking change because the following code is no longer accepted ``` rust // assume this type comes from a dependency // NOTE no derive(Hash) #[derive(Hash32)] struct Int(i32); let mut x = FnvIndexSet::<_, 4>::default(); let _ = x.insert(Int(0)); // error: does not implement Hash ``` Co-authored-by: Jorge Aparicio <[email protected]>
2 parents 9e2a792 + 7432dd9 commit 97ac129

File tree

9 files changed

+35
-44
lines changed

9 files changed

+35
-44
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111

1212
### Changed
1313

14+
- [breaking-change] `IndexMap` and `IndexSet` now require that keys implement the `core::hash::Hash`
15+
trait instead of the `hash32::Hash` (v0.2.0) trait
16+
1417
### Fixed
1518

1619
### Removed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ keywords = ["static", "no-heap"]
1212
license = "MIT OR Apache-2.0"
1313
name = "heapless"
1414
repository = "https://github.com/japaric/heapless"
15-
version = "0.7.16"
15+
version = "0.8.0"
1616

1717
[features]
1818
default = ["cas"]
@@ -40,7 +40,7 @@ atomic-polyfill = { version = "0.1.4" }
4040
atomic-polyfill = { version = "0.1.8", optional = true }
4141

4242
[dependencies]
43-
hash32 = "0.2.1"
43+
hash32 = "0.3.0"
4444

4545
[target.'cfg(target_arch = "x86_64")'.dependencies]
4646
spin = "0.9.2"

src/de.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
use crate::{
22
binary_heap::Kind as BinaryHeapKind, BinaryHeap, IndexMap, IndexSet, LinearMap, String, Vec,
33
};
4-
use core::{fmt, marker::PhantomData};
5-
use hash32::{BuildHasherDefault, Hash, Hasher};
4+
use core::{
5+
fmt,
6+
hash::{Hash, Hasher},
7+
marker::PhantomData,
8+
};
9+
use hash32::BuildHasherDefault;
610
use serde::de::{self, Deserialize, Deserializer, Error, MapAccess, SeqAccess};
711

812
// Sequential containers

src/indexmap.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
use core::{borrow::Borrow, fmt, iter::FromIterator, mem, num::NonZeroU32, ops, slice};
2-
3-
use hash32::{BuildHasher, BuildHasherDefault, FnvHasher, Hash, Hasher};
1+
use core::{
2+
borrow::Borrow,
3+
fmt,
4+
hash::{BuildHasher, Hash, Hasher as _},
5+
iter::FromIterator,
6+
mem,
7+
num::NonZeroU32,
8+
ops, slice,
9+
};
10+
11+
use hash32::{BuildHasherDefault, FnvHasher};
412

513
use crate::Vec;
614

src/indexset.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
use crate::indexmap::{self, IndexMap};
2-
use core::{borrow::Borrow, fmt, iter::FromIterator};
3-
use hash32::{BuildHasher, BuildHasherDefault, FnvHasher, Hash};
2+
use core::{
3+
borrow::Borrow,
4+
fmt,
5+
hash::{BuildHasher, Hash},
6+
iter::FromIterator,
7+
};
8+
use hash32::{BuildHasherDefault, FnvHasher};
49

510
/// A [`heapless::IndexSet`](./struct.IndexSet.html) using the
611
/// default FNV hasher.

src/ser.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
use core::hash::{BuildHasher, Hash};
2+
13
use crate::{
24
binary_heap::Kind as BinaryHeapKind, BinaryHeap, IndexMap, IndexSet, LinearMap, String, Vec,
35
};
4-
use hash32::{BuildHasher, Hash};
56
use serde::ser::{Serialize, SerializeMap, SerializeSeq, Serializer};
67

78
// Sequential containers

src/spsc.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -451,18 +451,6 @@ where
451451
}
452452
}
453453

454-
impl<T, const N: usize> hash32::Hash for Queue<T, N>
455-
where
456-
T: hash32::Hash,
457-
{
458-
fn hash<H: hash32::Hasher>(&self, state: &mut H) {
459-
// iterate over self in order
460-
for t in self.iter() {
461-
hash32::Hash::hash(t, state);
462-
}
463-
}
464-
}
465-
466454
impl<'a, T, const N: usize> IntoIterator for &'a Queue<T, N> {
467455
type Item = &'a T;
468456
type IntoIter = Iter<'a, T, N>;
@@ -590,8 +578,9 @@ impl<'a, T, const N: usize> Producer<'a, T, N> {
590578

591579
#[cfg(test)]
592580
mod tests {
581+
use std::hash::{Hash, Hasher};
582+
593583
use crate::spsc::Queue;
594-
use hash32::Hasher;
595584

596585
#[test]
597586
fn full() {
@@ -892,13 +881,13 @@ mod tests {
892881
};
893882
let hash1 = {
894883
let mut hasher1 = hash32::FnvHasher::default();
895-
hash32::Hash::hash(&rb1, &mut hasher1);
884+
rb1.hash(&mut hasher1);
896885
let hash1 = hasher1.finish();
897886
hash1
898887
};
899888
let hash2 = {
900889
let mut hasher2 = hash32::FnvHasher::default();
901-
hash32::Hash::hash(&rb2, &mut hasher2);
890+
rb2.hash(&mut hasher2);
902891
let hash2 = hasher2.finish();
903892
hash2
904893
};

src/string.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use core::{cmp::Ordering, fmt, fmt::Write, hash, iter, ops, str};
22

3-
use hash32;
4-
53
use crate::Vec;
64

75
/// A fixed capacity [`String`](https://doc.rust-lang.org/std/string/struct.String.html)
@@ -364,13 +362,6 @@ impl<const N: usize> hash::Hash for String<N> {
364362
}
365363
}
366364

367-
impl<const N: usize> hash32::Hash for String<N> {
368-
#[inline]
369-
fn hash<H: hash32::Hasher>(&self, hasher: &mut H) {
370-
<str as hash32::Hash>::hash(self, hasher)
371-
}
372-
}
373-
374365
impl<const N: usize> fmt::Write for String<N> {
375366
fn write_str(&mut self, s: &str) -> Result<(), fmt::Error> {
376367
self.push_str(s).map_err(|_| fmt::Error)

src/vec.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use core::{
22
cmp::Ordering, convert::TryFrom, fmt, hash, iter::FromIterator, mem::MaybeUninit, ops, ptr,
33
slice,
44
};
5-
use hash32;
65

76
/// A fixed capacity [`Vec`](https://doc.rust-lang.org/std/vec/struct.Vec.html)
87
///
@@ -898,15 +897,6 @@ where
898897
}
899898
}
900899

901-
impl<T, const N: usize> hash32::Hash for Vec<T, N>
902-
where
903-
T: hash32::Hash,
904-
{
905-
fn hash<H: hash32::Hasher>(&self, state: &mut H) {
906-
<[T] as hash32::Hash>::hash(self, state)
907-
}
908-
}
909-
910900
impl<'a, T, const N: usize> IntoIterator for &'a Vec<T, N> {
911901
type Item = &'a T;
912902
type IntoIter = slice::Iter<'a, T>;

0 commit comments

Comments
 (0)