Skip to content

Commit

Permalink
Remove workaround using inline consts (stable in 1.79)
Browse files Browse the repository at this point in the history
  • Loading branch information
sosthene-nitrokey committed Jun 14, 2024
1 parent ea956c2 commit 1fe4631
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ license = "Apache-2.0 OR MIT"
documentation = "https://docs.rs/interchange"
keywords = ["cortex-m", "nxp", "lpc"]
categories = ["development-tools", "embedded"]
rust-version = "1.79"

[target.'cfg(loom)'.dependencies]
loom = "0.5"
15 changes: 10 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,6 @@ pub struct Channel<Rq, Rp> {
}

impl<Rq, Rp> Channel<Rq, Rp> {
#[cfg(not(loom))]
const CHANNEL_INIT: Channel<Rq, Rp> = Self::new();

// Loom's atomics are not const :/
#[cfg(not(loom))]
pub const fn new() -> Self {
Expand Down Expand Up @@ -889,7 +886,16 @@ impl<Rq, Rp, const N: usize> Interchange<Rq, Rp, N> {
#[cfg(not(loom))]
pub const fn new() -> Self {
Self {
channels: [Channel::<Rq, Rp>::CHANNEL_INIT; N],
channels: [const { Channel::new() }; N],
last_claimed: AtomicUsize::new(0),
}
}

/// Create a new Interchange
#[cfg(loom)]
pub fn new() -> Self {
Self {
channels: core::array::from_fn(|_| Channel::new()),
last_claimed: AtomicUsize::new(0),
}
}
Expand Down Expand Up @@ -958,7 +964,6 @@ impl<'alloc, Rq, Rp> InterchangeRef<'alloc, Rq, Rp> {
}
}

#[cfg(not(loom))]
impl<Rq, Rp, const N: usize> Default for Interchange<Rq, Rp, N> {
fn default() -> Self {
Self::new()
Expand Down

0 comments on commit 1fe4631

Please sign in to comment.