From 4552c1b30080b5e7a735fee82c5416aae1743f04 Mon Sep 17 00:00:00 2001 From: Nicolas Stalder Date: Thu, 11 Feb 2021 21:30:39 +0100 Subject: [PATCH] Improve API using new Rust 1.50 feature --- .github/workflows/ci.yml | 6 ++++++ Cargo.toml | 2 +- src/lib.rs | 2 +- src/macros.rs | 12 +++++++----- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fdb8cc2..7d770eb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,6 +8,12 @@ jobs: steps: - uses: actions/checkout@master + - uses: actions-rs/toolchain@v1 + name: Install Rust + with: + profile: minimal + toolchain: stable + override: true - name: Build run: cargo build --verbose - name: Run tests diff --git a/Cargo.toml b/Cargo.toml index a435533..861ca09 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "interchange" -version = "0.1.1" +version = "0.1.2" authors = ["Nicolas Stalder "] edition = "2018" description = "Request/response mechanism for embedded development, using atomics" diff --git a/src/lib.rs b/src/lib.rs index d4e1760..8cf9d7b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -167,7 +167,7 @@ pub trait Interchange: Sized { fn claim() -> Option<(Requester, Responder)>; /// Method for debugging: how many allocated clients have not been claimed. - fn available_clients() -> usize; + fn unclaimed_clients() -> usize; /// Method purely for testing - do not use in production /// diff --git a/src/macros.rs b/src/macros.rs index abef396..bbd536f 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -29,10 +29,10 @@ #[macro_export] macro_rules! interchange { ($Name:ident: ($REQUEST:ty, $RESPONSE:ty)) => { - $crate::interchange!($Name: ($REQUEST, $RESPONSE, 1, [None])); + $crate::interchange!($Name: ($REQUEST, $RESPONSE, 1)); }; - ($Name:ident: ($REQUEST:ty, $RESPONSE:ty, $N:expr, $Nones:expr)) => { + ($Name:ident: ($REQUEST:ty, $RESPONSE:ty, $N:expr)) => { // TODO: figure out how to implement, e.g., Clone iff REQUEST // and RESPONSE are clone (do not introduce Clone, Debug, etc. trait bounds). @@ -49,8 +49,10 @@ macro_rules! interchange { use core::cell::UnsafeCell; // TODO(nickray): This turns up in .data section, fix this. - // static mut INTERCHANGES: [Option<$Name>; $N] = [None; $N]; - static mut INTERCHANGES: [Option<$Name>; $N] = $Nones; + + // yay Rust 1.50 + const NONE: Option<$Name> = None; + static mut INTERCHANGES: [Option<$Name>; $N] = [NONE; $N]; static mut STATES: [u8; $N] = [0u8; $N]; unsafe { let mut cell: MaybeUninit>> = MaybeUninit::uninit(); @@ -110,7 +112,7 @@ macro_rules! interchange { } } - fn available_clients() -> usize { + fn unclaimed_clients() -> usize { Self::CLIENT_CAPACITY - Self::last_claimed().load(core::sync::atomic::Ordering::SeqCst) }