Skip to content

Commit 4552c1b

Browse files
committed
Improve API using new Rust 1.50 feature
1 parent 0c0f433 commit 4552c1b

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ jobs:
88

99
steps:
1010
- uses: actions/checkout@master
11+
- uses: actions-rs/toolchain@v1
12+
name: Install Rust
13+
with:
14+
profile: minimal
15+
toolchain: stable
16+
override: true
1117
- name: Build
1218
run: cargo build --verbose
1319
- name: Run tests

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "interchange"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
authors = ["Nicolas Stalder <[email protected]>"]
55
edition = "2018"
66
description = "Request/response mechanism for embedded development, using atomics"

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ pub trait Interchange: Sized {
167167
fn claim() -> Option<(Requester<Self>, Responder<Self>)>;
168168

169169
/// Method for debugging: how many allocated clients have not been claimed.
170-
fn available_clients() -> usize;
170+
fn unclaimed_clients() -> usize;
171171

172172
/// Method purely for testing - do not use in production
173173
///

src/macros.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
#[macro_export]
3030
macro_rules! interchange {
3131
($Name:ident: ($REQUEST:ty, $RESPONSE:ty)) => {
32-
$crate::interchange!($Name: ($REQUEST, $RESPONSE, 1, [None]));
32+
$crate::interchange!($Name: ($REQUEST, $RESPONSE, 1));
3333
};
3434

35-
($Name:ident: ($REQUEST:ty, $RESPONSE:ty, $N:expr, $Nones:expr)) => {
35+
($Name:ident: ($REQUEST:ty, $RESPONSE:ty, $N:expr)) => {
3636

3737
// TODO: figure out how to implement, e.g., Clone iff REQUEST
3838
// and RESPONSE are clone (do not introduce Clone, Debug, etc. trait bounds).
@@ -49,8 +49,10 @@ macro_rules! interchange {
4949
use core::cell::UnsafeCell;
5050

5151
// TODO(nickray): This turns up in .data section, fix this.
52-
// static mut INTERCHANGES: [Option<$Name>; $N] = [None; $N];
53-
static mut INTERCHANGES: [Option<$Name>; $N] = $Nones;
52+
53+
// yay Rust 1.50
54+
const NONE: Option<$Name> = None;
55+
static mut INTERCHANGES: [Option<$Name>; $N] = [NONE; $N];
5456
static mut STATES: [u8; $N] = [0u8; $N];
5557
unsafe {
5658
let mut cell: MaybeUninit<UnsafeCell<&'static mut Option<$Name>>> = MaybeUninit::uninit();
@@ -110,7 +112,7 @@ macro_rules! interchange {
110112
}
111113
}
112114

113-
fn available_clients() -> usize {
115+
fn unclaimed_clients() -> usize {
114116
Self::CLIENT_CAPACITY - Self::last_claimed().load(core::sync::atomic::Ordering::SeqCst)
115117
}
116118

0 commit comments

Comments
 (0)