From 58cb279aeca29222f773526b92fab18e5c34b4b7 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Mon, 19 Apr 2021 21:31:47 +0200 Subject: [PATCH] IndexMap::new() is now a const-fn --- CHANGELOG.md | 1 + Cargo.toml | 2 +- src/indexmap.rs | 22 ++++------------------ src/string.rs | 32 -------------------------------- 4 files changed, 6 insertions(+), 51 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c1c72846..2d2d0527 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - `Pool` and `MPMC` now works on `thumbv6m` - [breaking-change] `String` has had `utf8` related methods removed as this can be done via `str` - [breaking-change] No data structures implement `AsSlice` traits any more, now using `AsRef` and `AsMut` +- `IndexMap::new()` is now a `const-fn` ## [v0.6.1] - 2021-03-02 diff --git a/Cargo.toml b/Cargo.toml index 312d3cce..f4c66eb0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,7 +36,7 @@ scoped_threadpool = "0.1.8" atomic-polyfill = "0.1.2" [dependencies] -hash32 = "0.1.0" +hash32 = "0.2.1" [dependencies.serde] version = "1" diff --git a/src/indexmap.rs b/src/indexmap.rs index 1a3d2e14..100d7009 100644 --- a/src/indexmap.rs +++ b/src/indexmap.rs @@ -360,25 +360,16 @@ where /// println!("{}: \"{}\"", book, review); /// } /// ``` -pub struct IndexMap -where - K: Eq + Hash, -{ +pub struct IndexMap { core: CoreMap, build_hasher: S, } -impl IndexMap, N> -where - K: Eq + Hash, - S: Default + Hasher, -{ +impl IndexMap, N> { /// Creates an empty `IndexMap`. - /// - /// **NOTE** This constructor will become a `const fn` in the future - pub fn new() -> Self { + pub const fn new() -> Self { IndexMap { - build_hasher: BuildHasherDefault::default(), + build_hasher: BuildHasherDefault::new(), core: CoreMap::new(), } } @@ -737,7 +728,6 @@ where K: Eq + Hash + Borrow, Q: ?Sized + Eq + Hash, S: BuildHasher, - // N: ArrayLength> + ArrayLength>, { type Output = V; @@ -751,7 +741,6 @@ where K: Eq + Hash + Borrow, Q: ?Sized + Eq + Hash, S: BuildHasher, - // N: ArrayLength> + ArrayLength>, { fn index_mut(&mut self, key: &Q) -> &mut V { self.get_mut(key).expect("key not found") @@ -763,7 +752,6 @@ where K: Eq + Hash + Clone, V: Clone, S: Clone, - // N: ArrayLength> + ArrayLength>, { fn clone(&self) -> Self { Self { @@ -778,7 +766,6 @@ where K: Eq + Hash + fmt::Debug, V: fmt::Debug, S: BuildHasher, - // N: ArrayLength> + ArrayLength>, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_map().entries(self.iter()).finish() @@ -789,7 +776,6 @@ impl Default for IndexMap where K: Eq + Hash, S: BuildHasher + Default, - // N: ArrayLength> + ArrayLength>, { fn default() -> Self { IndexMap { diff --git a/src/string.rs b/src/string.rs index 23735fce..5848095d 100644 --- a/src/string.rs +++ b/src/string.rs @@ -389,38 +389,6 @@ impl PartialEq> for String { } } -// macro_rules! impl_eq { -// ($lhs:ty, $rhs:ty) => { -// impl<'a, 'b, N> PartialEq<$rhs> for $lhs -// where -// N: ArrayLength, -// { -// #[inline] -// fn eq(&self, other: &$rhs) -> bool { -// str::eq(&self[..], &other[..]) -// } -// #[inline] -// fn ne(&self, other: &$rhs) -> bool { -// str::ne(&self[..], &other[..]) -// } -// } - -// impl<'a, 'b, N> PartialEq<$lhs> for $rhs -// where -// N: ArrayLength, -// { -// #[inline] -// fn eq(&self, other: &$lhs) -> bool { -// str::eq(&self[..], &other[..]) -// } -// #[inline] -// fn ne(&self, other: &$lhs) -> bool { -// str::ne(&self[..], &other[..]) -// } -// } -// }; -// } - // String == str impl PartialEq for String { #[inline]