Skip to content

Commit 58cb279

Browse files
committed
IndexMap::new() is now a const-fn
1 parent 6fdcc4f commit 58cb279

File tree

4 files changed

+6
-51
lines changed

4 files changed

+6
-51
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1818
- `Pool` and `MPMC` now works on `thumbv6m`
1919
- [breaking-change] `String` has had `utf8` related methods removed as this can be done via `str`
2020
- [breaking-change] No data structures implement `AsSlice` traits any more, now using `AsRef` and `AsMut`
21+
- `IndexMap::new()` is now a `const-fn`
2122

2223
## [v0.6.1] - 2021-03-02
2324

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ scoped_threadpool = "0.1.8"
3636
atomic-polyfill = "0.1.2"
3737

3838
[dependencies]
39-
hash32 = "0.1.0"
39+
hash32 = "0.2.1"
4040

4141
[dependencies.serde]
4242
version = "1"

src/indexmap.rs

+4-18
Original file line numberDiff line numberDiff line change
@@ -360,25 +360,16 @@ where
360360
/// println!("{}: \"{}\"", book, review);
361361
/// }
362362
/// ```
363-
pub struct IndexMap<K, V, S, const N: usize>
364-
where
365-
K: Eq + Hash,
366-
{
363+
pub struct IndexMap<K, V, S, const N: usize> {
367364
core: CoreMap<K, V, N>,
368365
build_hasher: S,
369366
}
370367

371-
impl<K, V, S, const N: usize> IndexMap<K, V, BuildHasherDefault<S>, N>
372-
where
373-
K: Eq + Hash,
374-
S: Default + Hasher,
375-
{
368+
impl<K, V, S, const N: usize> IndexMap<K, V, BuildHasherDefault<S>, N> {
376369
/// Creates an empty `IndexMap`.
377-
///
378-
/// **NOTE** This constructor will become a `const fn` in the future
379-
pub fn new() -> Self {
370+
pub const fn new() -> Self {
380371
IndexMap {
381-
build_hasher: BuildHasherDefault::default(),
372+
build_hasher: BuildHasherDefault::new(),
382373
core: CoreMap::new(),
383374
}
384375
}
@@ -737,7 +728,6 @@ where
737728
K: Eq + Hash + Borrow<Q>,
738729
Q: ?Sized + Eq + Hash,
739730
S: BuildHasher,
740-
// N: ArrayLength<Bucket<K, V>> + ArrayLength<Option<Pos>>,
741731
{
742732
type Output = V;
743733

@@ -751,7 +741,6 @@ where
751741
K: Eq + Hash + Borrow<Q>,
752742
Q: ?Sized + Eq + Hash,
753743
S: BuildHasher,
754-
// N: ArrayLength<Bucket<K, V>> + ArrayLength<Option<Pos>>,
755744
{
756745
fn index_mut(&mut self, key: &Q) -> &mut V {
757746
self.get_mut(key).expect("key not found")
@@ -763,7 +752,6 @@ where
763752
K: Eq + Hash + Clone,
764753
V: Clone,
765754
S: Clone,
766-
// N: ArrayLength<Bucket<K, V>> + ArrayLength<Option<Pos>>,
767755
{
768756
fn clone(&self) -> Self {
769757
Self {
@@ -778,7 +766,6 @@ where
778766
K: Eq + Hash + fmt::Debug,
779767
V: fmt::Debug,
780768
S: BuildHasher,
781-
// N: ArrayLength<Bucket<K, V>> + ArrayLength<Option<Pos>>,
782769
{
783770
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
784771
f.debug_map().entries(self.iter()).finish()
@@ -789,7 +776,6 @@ impl<K, V, S, const N: usize> Default for IndexMap<K, V, S, N>
789776
where
790777
K: Eq + Hash,
791778
S: BuildHasher + Default,
792-
// N: ArrayLength<Bucket<K, V>> + ArrayLength<Option<Pos>>,
793779
{
794780
fn default() -> Self {
795781
IndexMap {

src/string.rs

-32
Original file line numberDiff line numberDiff line change
@@ -389,38 +389,6 @@ impl<const N1: usize, const N2: usize> PartialEq<String<N2>> for String<N1> {
389389
}
390390
}
391391

392-
// macro_rules! impl_eq {
393-
// ($lhs:ty, $rhs:ty) => {
394-
// impl<'a, 'b, N> PartialEq<$rhs> for $lhs
395-
// where
396-
// N: ArrayLength<u8>,
397-
// {
398-
// #[inline]
399-
// fn eq(&self, other: &$rhs) -> bool {
400-
// str::eq(&self[..], &other[..])
401-
// }
402-
// #[inline]
403-
// fn ne(&self, other: &$rhs) -> bool {
404-
// str::ne(&self[..], &other[..])
405-
// }
406-
// }
407-
408-
// impl<'a, 'b, N> PartialEq<$lhs> for $rhs
409-
// where
410-
// N: ArrayLength<u8>,
411-
// {
412-
// #[inline]
413-
// fn eq(&self, other: &$lhs) -> bool {
414-
// str::eq(&self[..], &other[..])
415-
// }
416-
// #[inline]
417-
// fn ne(&self, other: &$lhs) -> bool {
418-
// str::ne(&self[..], &other[..])
419-
// }
420-
// }
421-
// };
422-
// }
423-
424392
// String<N> == str
425393
impl<const N: usize> PartialEq<str> for String<N> {
426394
#[inline]

0 commit comments

Comments
 (0)