Skip to content

Commit 6dcedb8

Browse files
committed
Fixes for min const generics
1 parent f962e3a commit 6dcedb8

File tree

5 files changed

+19
-94
lines changed

5 files changed

+19
-94
lines changed

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ __trybuild = []
3232
scoped_threadpool = "0.1.8"
3333

3434
[dependencies]
35-
as-slice = "0.1.0"
36-
# generic-array = "0.13.0"
35+
as-slice = "0.2.0"
3736
hash32 = "0.1.0"
3837

3938
[dependencies.serde]

src/binary_heap.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,12 @@ pub enum Max {}
7272
/// assert!(heap.is_empty())
7373
/// ```
7474
75-
pub struct BinaryHeap<T, K, const N: usize>
76-
where
77-
T: Ord,
78-
K: Kind,
79-
{
75+
pub struct BinaryHeap<T, K, const N: usize> {
8076
pub(crate) _kind: PhantomData<K>,
8177
pub(crate) data: Vec<T, N>,
8278
}
8379

84-
impl<T, K, const N: usize> BinaryHeap<T, K, N>
85-
where
86-
T: Ord,
87-
K: Kind,
88-
{
80+
impl<T, K, const N: usize> BinaryHeap<T, K, N> {
8981
/* Constructors */
9082
/// Creates an empty BinaryHeap as a $K-heap.
9183
///
@@ -105,7 +97,13 @@ where
10597
data: Vec::new(),
10698
}
10799
}
100+
}
108101

102+
impl<T, K, const N: usize> BinaryHeap<T, K, N>
103+
where
104+
T: Ord,
105+
K: Kind,
106+
{
109107
/* Public API */
110108
/// Returns the capacity of the binary heap.
111109
pub fn capacity(&self) -> usize {
@@ -512,11 +510,7 @@ where
512510
}
513511
}
514512

515-
impl<T, K, const N: usize> Drop for BinaryHeap<T, K, N>
516-
where
517-
K: Kind,
518-
T: Ord,
519-
{
513+
impl<T, K, const N: usize> Drop for BinaryHeap<T, K, N> {
520514
fn drop(&mut self) {
521515
unsafe { ptr::drop_in_place(self.data.as_mut_slice()) }
522516
}

src/i.rs

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/lib.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,13 @@
6767
//! It *might* compile on older versions but that may change in any new patch release.
6868
6969
// experimental usage of const generics, requires nightly 2020-08-18 (or newer)
70-
#![feature(min_const_generics)]
71-
#![feature(const_fn)]
7270
#![cfg_attr(not(test), no_std)]
7371
#![deny(missing_docs)]
7472
#![deny(rust_2018_compatibility)]
7573
#![deny(rust_2018_idioms)]
7674
// #![deny(warnings)]
7775

7876
pub use binary_heap::BinaryHeap;
79-
// pub use generic_array::typenum::{consts, PowerOfTwo};
80-
// pub use generic_array::ArrayLength;
8177
pub use histbuf::HistoryBuffer;
8278
pub use indexmap::{Bucket, FnvIndexMap, IndexMap, Pos};
8379
pub use indexset::{FnvIndexSet, IndexSet};
@@ -99,10 +95,9 @@ mod de;
9995
mod ser;
10096

10197
pub mod binary_heap;
102-
// pub mod i;
10398
#[cfg(all(has_cas, feature = "cas"))]
10499
pub mod mpmc;
105-
// #[cfg(all(has_cas, feature = "cas"))]
100+
#[cfg(all(has_cas, feature = "cas"))]
106101
pub mod pool;
107102
#[cfg(has_atomics)]
108103
pub mod spsc;

src/linear_map.rs

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,11 @@ use crate::Vec;
1212
///
1313
/// Note that as this map doesn't use hashing so most operations are **O(N)** instead of O(1)
1414
15-
pub struct LinearMap<K, V, const N: usize>
16-
where
17-
K: Eq,
18-
{
15+
pub struct LinearMap<K, V, const N: usize> {
1916
pub(crate) buffer: Vec<(K, V), N>,
2017
}
2118

22-
impl<K, V, const N: usize> LinearMap<K, V, N>
23-
where
24-
K: Eq,
25-
{
19+
impl<K, V, const N: usize> LinearMap<K, V, N> {
2620
/// Creates an empty `LinearMap`
2721
///
2822
/// # Examples
@@ -39,7 +33,12 @@ where
3933
pub const fn new() -> Self {
4034
Self { buffer: Vec::new() }
4135
}
36+
}
4237

38+
impl<K, V, const N: usize> LinearMap<K, V, N>
39+
where
40+
K: Eq,
41+
{
4342
/// Returns the number of elements that the map can hold
4443
///
4544
/// Computes in **O(1)** time
@@ -437,25 +436,6 @@ where
437436
}
438437
}
439438

440-
// TODO: Why is this needed at all, no example, no test... I don't get it
441-
// impl<K, V, const N: usize> IntoIterator for LinearMap<K, V, N>
442-
// where
443-
// K: Eq,
444-
// {
445-
// type Item = (K, V);
446-
// type IntoIter = IntoIter<K, V, N>;
447-
448-
// fn into_iter(mut self) -> Self::IntoIter {
449-
// // FIXME this may result in a memcpy at runtime
450-
// let lm = mem::replace(&mut self, unsafe { MaybeUninit::uninit().assume_init() });
451-
// mem::forget(self);
452-
453-
// Self::IntoIter {
454-
// inner: lm.buffer.into_iter(),
455-
// }
456-
// }
457-
// }
458-
459439
impl<'a, K, V, const N: usize> IntoIterator for &'a LinearMap<K, V, N>
460440
where
461441
K: Eq,
@@ -488,10 +468,7 @@ impl<'a, K, V> Clone for Iter<'a, K, V> {
488468
}
489469
}
490470

491-
impl<K, V, const N: usize> Drop for LinearMap<K, V, N>
492-
where
493-
K: Eq,
494-
{
471+
impl<K, V, const N: usize> Drop for LinearMap<K, V, N> {
495472
fn drop(&mut self) {
496473
// heapless::Vec implements drop right?
497474
drop(&self.buffer);

0 commit comments

Comments
 (0)