mirror of
https://github.com/rust-embedded/heapless.git
synced 2025-09-26 20:10:24 +00:00
Merge pull request #260 from japaric/fix-index-structs
Fix bounds in IndexMap and IndexSet, IndexSet::new() is now const
This commit is contained in:
commit
f3af76d607
12
CHANGELOG.md
12
CHANGELOG.md
@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [v0.7.9] - 2021-12-16
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix `IndexMap` and `IndexSet` bounds
|
||||
- Make `IndexSet::new()` a `const fn`
|
||||
|
||||
## [v0.7.8] - 2021-11-11
|
||||
|
||||
### Added
|
||||
@ -423,8 +430,9 @@ architecture.
|
||||
|
||||
- Initial release
|
||||
|
||||
[Unreleased]: https://github.com/japaric/heapless/compare/v0.7.8...HEAD
|
||||
[v0.7.9]: https://github.com/japaric/heapless/compare/v0.7.7...v0.7.8
|
||||
[Unreleased]: https://github.com/japaric/heapless/compare/v0.7.9...HEAD
|
||||
[v0.7.9]: https://github.com/japaric/heapless/compare/v0.7.8...v0.7.9
|
||||
[v0.7.8]: https://github.com/japaric/heapless/compare/v0.7.7...v0.7.8
|
||||
[v0.7.7]: https://github.com/japaric/heapless/compare/v0.7.6...v0.7.7
|
||||
[v0.7.6]: https://github.com/japaric/heapless/compare/v0.7.5...v0.7.6
|
||||
[v0.7.5]: https://github.com/japaric/heapless/compare/v0.7.4...v0.7.5
|
||||
|
@ -12,7 +12,7 @@ keywords = ["static", "no-heap"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
name = "heapless"
|
||||
repository = "https://github.com/japaric/heapless"
|
||||
version = "0.7.8"
|
||||
version = "0.7.9"
|
||||
|
||||
[features]
|
||||
default = ["cas"]
|
||||
|
@ -368,6 +368,10 @@ pub struct IndexMap<K, V, S, const N: usize> {
|
||||
impl<K, V, S, const N: usize> IndexMap<K, V, BuildHasherDefault<S>, N> {
|
||||
/// Creates an empty `IndexMap`.
|
||||
pub const fn new() -> Self {
|
||||
// Const assert
|
||||
crate::sealed::greater_than_1::<N>();
|
||||
crate::sealed::power_of_two::<N>();
|
||||
|
||||
IndexMap {
|
||||
build_hasher: BuildHasherDefault::new(),
|
||||
core: CoreMap::new(),
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::indexmap::{self, IndexMap};
|
||||
use core::{borrow::Borrow, fmt, iter::FromIterator};
|
||||
use hash32::{BuildHasher, BuildHasherDefault, FnvHasher, Hash, Hasher};
|
||||
use hash32::{BuildHasher, BuildHasherDefault, FnvHasher, Hash};
|
||||
|
||||
/// A [`heapless::IndexSet`](./struct.IndexSet.html) using the
|
||||
/// default FNV hasher.
|
||||
@ -74,22 +74,13 @@ pub type FnvIndexSet<T, const N: usize> = IndexSet<T, BuildHasherDefault<FnvHash
|
||||
/// println!("{}", book);
|
||||
/// }
|
||||
/// ```
|
||||
pub struct IndexSet<T, S, const N: usize>
|
||||
where
|
||||
T: Eq + Hash,
|
||||
{
|
||||
pub struct IndexSet<T, S, const N: usize> {
|
||||
map: IndexMap<T, (), S, N>,
|
||||
}
|
||||
|
||||
impl<T, S, const N: usize> IndexSet<T, BuildHasherDefault<S>, N>
|
||||
where
|
||||
T: Eq + Hash,
|
||||
S: Default + Hasher,
|
||||
{
|
||||
impl<T, S, const N: usize> IndexSet<T, BuildHasherDefault<S>, N> {
|
||||
/// Creates an empty `IndexSet`
|
||||
pub fn new() -> Self {
|
||||
assert!(N.is_power_of_two());
|
||||
|
||||
pub const fn new() -> Self {
|
||||
IndexSet {
|
||||
map: IndexMap::new(),
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user