Skip to content

Commit

Permalink
Preparing v0.7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
korken89 committed Jun 30, 2021
1 parent 22e4c73 commit 295e115
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 2 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [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

### Changed
Expand Down Expand Up @@ -358,7 +365,8 @@ architecture.

- 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.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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -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.1"
version = "0.7.2"

[features]
default = ["cas"]
Expand Down
3 changes: 3 additions & 0 deletions src/histbuf.rs
Expand Up @@ -58,6 +58,9 @@ impl<T, const N: usize> HistoryBuffer<T, N> {
/// ```
#[inline]
pub const fn new() -> Self {
// Const assert
crate::sealed::greater_than_0::<N>();

Self {
data: [Self::INIT; N],
write_at: 0,
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Expand Up @@ -71,6 +71,7 @@
#![deny(rust_2018_compatibility)]
#![deny(rust_2018_idioms)]
#![deny(warnings)]
#![deny(const_err)]

pub use binary_heap::BinaryHeap;
pub use histbuf::HistoryBuffer;
Expand Down
3 changes: 3 additions & 0 deletions src/mpmc.rs
Expand Up @@ -137,6 +137,9 @@ impl<T, const N: usize> MpMcQueue<T, N> {

/// Creates an empty queue
pub const fn new() -> Self {
// Const assert
crate::sealed::greater_than_0::<N>();

// Const assert on size.
Self::ASSERT[!(N < (IntSize::MAX as usize)) as usize];

Expand Down
37 changes: 37 additions & 0 deletions src/sealed.rs
Expand Up @@ -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;
}
3 changes: 3 additions & 0 deletions src/spsc.rs
Expand Up @@ -116,6 +116,9 @@ impl<T, const N: usize> Queue<T, N> {

/// Creates an empty queue with a fixed capacity of `N - 1`
pub const fn new() -> Self {
// Const assert N > 1
crate::sealed::greater_than_1::<N>();

Queue {
head: AtomicUsize::new(0),
tail: AtomicUsize::new(0),
Expand Down
3 changes: 3 additions & 0 deletions src/vec.rs
Expand Up @@ -53,6 +53,9 @@ impl<T, const N: usize> Vec<T, N> {
/// ```
/// `Vec` `const` constructor; wrap the returned value in [`Vec`](../struct.Vec.html)
pub const fn new() -> Self {
// Const assert N > 0
crate::sealed::greater_than_0::<N>();

Self {
buffer: [Self::INIT; N],
len: 0,
Expand Down

0 comments on commit 295e115

Please sign in to comment.