Preparing v0.7.2

This commit is contained in:
Emil Fresk 2021-06-30 16:57:01 +02:00
parent 22e4c73383
commit 295e115542
8 changed files with 60 additions and 2 deletions

View File

@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased] ## [Unreleased]
## [v0.7.2] - 2021-06-30
### Added
- Added new `Vec::into_array` method
- Added const-asserts to all data structures
## [v0.7.1] - 2021-05-23 ## [v0.7.1] - 2021-05-23
### Changed ### Changed
@ -358,7 +365,8 @@ architecture.
- Initial release - Initial release
[Unreleased]: https://github.com/japaric/heapless/compare/v0.7.1...HEAD [Unreleased]: https://github.com/japaric/heapless/compare/v0.7.2...HEAD
[v0.7.2]: https://github.com/japaric/heapless/compare/v0.7.1...v0.7.2
[v0.7.1]: https://github.com/japaric/heapless/compare/v0.7.0...v0.7.1 [v0.7.1]: https://github.com/japaric/heapless/compare/v0.7.0...v0.7.1
[v0.7.0]: https://github.com/japaric/heapless/compare/v0.6.1...v0.7.0 [v0.7.0]: https://github.com/japaric/heapless/compare/v0.6.1...v0.7.0
[v0.6.1]: https://github.com/japaric/heapless/compare/v0.6.0...v0.6.1 [v0.6.1]: https://github.com/japaric/heapless/compare/v0.6.0...v0.6.1

View File

@ -12,7 +12,7 @@ keywords = ["static", "no-heap"]
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
name = "heapless" name = "heapless"
repository = "https://github.com/japaric/heapless" repository = "https://github.com/japaric/heapless"
version = "0.7.1" version = "0.7.2"
[features] [features]
default = ["cas"] default = ["cas"]

View File

@ -58,6 +58,9 @@ impl<T, const N: usize> HistoryBuffer<T, N> {
/// ``` /// ```
#[inline] #[inline]
pub const fn new() -> Self { pub const fn new() -> Self {
// Const assert
crate::sealed::greater_than_0::<N>();
Self { Self {
data: [Self::INIT; N], data: [Self::INIT; N],
write_at: 0, write_at: 0,

View File

@ -71,6 +71,7 @@
#![deny(rust_2018_compatibility)] #![deny(rust_2018_compatibility)]
#![deny(rust_2018_idioms)] #![deny(rust_2018_idioms)]
#![deny(warnings)] #![deny(warnings)]
#![deny(const_err)]
pub use binary_heap::BinaryHeap; pub use binary_heap::BinaryHeap;
pub use histbuf::HistoryBuffer; pub use histbuf::HistoryBuffer;

View File

@ -137,6 +137,9 @@ impl<T, const N: usize> MpMcQueue<T, N> {
/// Creates an empty queue /// Creates an empty queue
pub const fn new() -> Self { pub const fn new() -> Self {
// Const assert
crate::sealed::greater_than_0::<N>();
// Const assert on size. // Const assert on size.
Self::ASSERT[!(N < (IntSize::MAX as usize)) as usize]; Self::ASSERT[!(N < (IntSize::MAX as usize)) as usize];

View File

@ -21,3 +21,40 @@ pub mod binary_heap {
} }
} }
} }
#[allow(dead_code)]
#[allow(path_statements)]
pub(crate) const fn greater_than_0<const N: usize>() {
Assert::<N, 0>::GREATER;
}
#[allow(dead_code)]
#[allow(path_statements)]
pub(crate) const fn greater_than_1<const N: usize>() {
Assert::<N, 1>::GREATER;
}
#[allow(dead_code)]
/// Const assert hack
pub struct Assert<const L: usize, const R: usize>;
#[allow(dead_code)]
impl<const L: usize, const R: usize> Assert<L, R> {
/// Const assert hack
pub const GREATER_EQ: usize = L - R;
/// Const assert hack
pub const LESS_EQ: usize = R - L;
/// Const assert hack
pub const NOT_EQ: isize = 0 / (R as isize - L as isize);
/// Const assert hack
pub const EQ: usize = (R - L) + (L - R);
/// Const assert hack
pub const GREATER: usize = L - R - 1;
/// Const assert hack
pub const LESS: usize = R - L - 1;
}

View File

@ -116,6 +116,9 @@ impl<T, const N: usize> Queue<T, N> {
/// Creates an empty queue with a fixed capacity of `N - 1` /// Creates an empty queue with a fixed capacity of `N - 1`
pub const fn new() -> Self { pub const fn new() -> Self {
// Const assert N > 1
crate::sealed::greater_than_1::<N>();
Queue { Queue {
head: AtomicUsize::new(0), head: AtomicUsize::new(0),
tail: AtomicUsize::new(0), tail: AtomicUsize::new(0),

View File

@ -53,6 +53,9 @@ impl<T, const N: usize> Vec<T, N> {
/// ``` /// ```
/// `Vec` `const` constructor; wrap the returned value in [`Vec`](../struct.Vec.html) /// `Vec` `const` constructor; wrap the returned value in [`Vec`](../struct.Vec.html)
pub const fn new() -> Self { pub const fn new() -> Self {
// Const assert N > 0
crate::sealed::greater_than_0::<N>();
Self { Self {
buffer: [Self::INIT; N], buffer: [Self::INIT; N],
len: 0, len: 0,