mirror of
https://github.com/rust-embedded/heapless.git
synced 2025-10-02 14:54:30 +00:00
IndexMap::new() is now a const-fn
This commit is contained in:
parent
6fdcc4fb99
commit
58cb279aec
@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
- `Pool` and `MPMC` now works on `thumbv6m`
|
- `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] `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`
|
- [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
|
## [v0.6.1] - 2021-03-02
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ scoped_threadpool = "0.1.8"
|
|||||||
atomic-polyfill = "0.1.2"
|
atomic-polyfill = "0.1.2"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
hash32 = "0.1.0"
|
hash32 = "0.2.1"
|
||||||
|
|
||||||
[dependencies.serde]
|
[dependencies.serde]
|
||||||
version = "1"
|
version = "1"
|
||||||
|
@ -360,25 +360,16 @@ where
|
|||||||
/// println!("{}: \"{}\"", book, review);
|
/// println!("{}: \"{}\"", book, review);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub struct IndexMap<K, V, S, const N: usize>
|
pub struct IndexMap<K, V, S, const N: usize> {
|
||||||
where
|
|
||||||
K: Eq + Hash,
|
|
||||||
{
|
|
||||||
core: CoreMap<K, V, N>,
|
core: CoreMap<K, V, N>,
|
||||||
build_hasher: S,
|
build_hasher: S,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<K, V, S, const N: usize> IndexMap<K, V, BuildHasherDefault<S>, N>
|
impl<K, V, S, const N: usize> IndexMap<K, V, BuildHasherDefault<S>, N> {
|
||||||
where
|
|
||||||
K: Eq + Hash,
|
|
||||||
S: Default + Hasher,
|
|
||||||
{
|
|
||||||
/// Creates an empty `IndexMap`.
|
/// Creates an empty `IndexMap`.
|
||||||
///
|
pub const fn new() -> Self {
|
||||||
/// **NOTE** This constructor will become a `const fn` in the future
|
|
||||||
pub fn new() -> Self {
|
|
||||||
IndexMap {
|
IndexMap {
|
||||||
build_hasher: BuildHasherDefault::default(),
|
build_hasher: BuildHasherDefault::new(),
|
||||||
core: CoreMap::new(),
|
core: CoreMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -737,7 +728,6 @@ where
|
|||||||
K: Eq + Hash + Borrow<Q>,
|
K: Eq + Hash + Borrow<Q>,
|
||||||
Q: ?Sized + Eq + Hash,
|
Q: ?Sized + Eq + Hash,
|
||||||
S: BuildHasher,
|
S: BuildHasher,
|
||||||
// N: ArrayLength<Bucket<K, V>> + ArrayLength<Option<Pos>>,
|
|
||||||
{
|
{
|
||||||
type Output = V;
|
type Output = V;
|
||||||
|
|
||||||
@ -751,7 +741,6 @@ where
|
|||||||
K: Eq + Hash + Borrow<Q>,
|
K: Eq + Hash + Borrow<Q>,
|
||||||
Q: ?Sized + Eq + Hash,
|
Q: ?Sized + Eq + Hash,
|
||||||
S: BuildHasher,
|
S: BuildHasher,
|
||||||
// N: ArrayLength<Bucket<K, V>> + ArrayLength<Option<Pos>>,
|
|
||||||
{
|
{
|
||||||
fn index_mut(&mut self, key: &Q) -> &mut V {
|
fn index_mut(&mut self, key: &Q) -> &mut V {
|
||||||
self.get_mut(key).expect("key not found")
|
self.get_mut(key).expect("key not found")
|
||||||
@ -763,7 +752,6 @@ where
|
|||||||
K: Eq + Hash + Clone,
|
K: Eq + Hash + Clone,
|
||||||
V: Clone,
|
V: Clone,
|
||||||
S: Clone,
|
S: Clone,
|
||||||
// N: ArrayLength<Bucket<K, V>> + ArrayLength<Option<Pos>>,
|
|
||||||
{
|
{
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
Self {
|
Self {
|
||||||
@ -778,7 +766,6 @@ where
|
|||||||
K: Eq + Hash + fmt::Debug,
|
K: Eq + Hash + fmt::Debug,
|
||||||
V: fmt::Debug,
|
V: fmt::Debug,
|
||||||
S: BuildHasher,
|
S: BuildHasher,
|
||||||
// N: ArrayLength<Bucket<K, V>> + ArrayLength<Option<Pos>>,
|
|
||||||
{
|
{
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
f.debug_map().entries(self.iter()).finish()
|
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>
|
|||||||
where
|
where
|
||||||
K: Eq + Hash,
|
K: Eq + Hash,
|
||||||
S: BuildHasher + Default,
|
S: BuildHasher + Default,
|
||||||
// N: ArrayLength<Bucket<K, V>> + ArrayLength<Option<Pos>>,
|
|
||||||
{
|
{
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
IndexMap {
|
IndexMap {
|
||||||
|
@ -389,38 +389,6 @@ impl<const N1: usize, const N2: usize> PartialEq<String<N2>> for String<N1> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// macro_rules! impl_eq {
|
|
||||||
// ($lhs:ty, $rhs:ty) => {
|
|
||||||
// impl<'a, 'b, N> PartialEq<$rhs> for $lhs
|
|
||||||
// where
|
|
||||||
// N: ArrayLength<u8>,
|
|
||||||
// {
|
|
||||||
// #[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<u8>,
|
|
||||||
// {
|
|
||||||
// #[inline]
|
|
||||||
// fn eq(&self, other: &$lhs) -> bool {
|
|
||||||
// str::eq(&self[..], &other[..])
|
|
||||||
// }
|
|
||||||
// #[inline]
|
|
||||||
// fn ne(&self, other: &$lhs) -> bool {
|
|
||||||
// str::ne(&self[..], &other[..])
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|
||||||
// String<N> == str
|
// String<N> == str
|
||||||
impl<const N: usize> PartialEq<str> for String<N> {
|
impl<const N: usize> PartialEq<str> for String<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user