Skip to content

Commit 9be71fe

Browse files
committed
Improve docs, hide async features behind single async feature flag
Signed-off-by: jonas loeffelholz <jonas.loeffelholz@9elements.com> Signed-off-by: Marvin Gudel <marvin.gudel@9elements.com>
1 parent 7a87854 commit 9be71fe

6 files changed

Lines changed: 41 additions & 45 deletions

File tree

mctp-estack/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,4 @@ default = ["log"]
3434
std = ["mctp/std"]
3535
log = ["dep:log"]
3636
defmt = ["mctp/defmt", "dep:defmt" ]
37-
embassy = ["dep:embassy-sync", "async"]
38-
async = ["dep:embedded-io-async"]
37+
async = ["dep:embedded-io-async", "dep:embassy-sync"]

mctp-estack/src/control.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
//! MCTP Control Protocol implementation
88
99
use crate::fmt::*;
10-
#[cfg(feature = "embassy")]
10+
#[cfg(feature = "async")]
1111
use crate::Router;
12-
#[cfg(feature = "embassy")]
12+
#[cfg(feature = "async")]
1313
use mctp::{AsyncRespChannel, MsgIC};
1414
use mctp::{Eid, Error, Listener, MsgType};
1515
use uuid::Uuid;
@@ -194,9 +194,9 @@ pub struct MctpControlMsg<'a> {
194194
work: [u8; 2],
195195
}
196196

197-
#[cfg(feature = "embassy")]
197+
#[cfg(feature = "async")]
198198
const MAX_MSG_SIZE: usize = 20; /* largest is Get Endpoint UUID */
199-
#[cfg(feature = "embassy")]
199+
#[cfg(feature = "async")]
200200
const MAX_MSG_TYPES: usize = 8;
201201

202202
impl<'a> MctpControlMsg<'a> {
@@ -429,15 +429,15 @@ where
429429
}
430430

431431
/// A Control Message handler.
432-
#[cfg(feature = "embassy")]
432+
#[cfg(feature = "async")]
433433
pub struct MctpControl<'g, 'r> {
434434
rsp_buf: [u8; MAX_MSG_SIZE],
435435
types: heapless::Vec<MsgType, MAX_MSG_TYPES>,
436436
uuid: Option<Uuid>,
437437
router: &'g Router<'r>,
438438
}
439439

440-
#[cfg(feature = "embassy")]
440+
#[cfg(feature = "async")]
441441
impl<'g, 'r> MctpControl<'g, 'r> {
442442
/// Create a new instance.
443443
pub fn new(router: &'g Router<'r>) -> Self {

mctp-estack/src/lib.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,22 @@
55

66
//! # MCTP Stack
77
//!
8-
//! This crate provides a MCTP stack that can be embedded in other programs
9-
//! or devices.
10-
//! A `async` Router for embassy based applications is available
11-
//! through the `embassy` feature.
12-
//!
13-
//! A [`Router`] object lets programs use a [`Stack`] with
14-
//! MCTP transport binding links. Each *Port* handles transmitting and receiving
15-
//! packets independently. Messages destined for the stack's own EID will
16-
//! be passed to applications.
17-
//!
18-
//! Applications can create [`router::RouterAsyncListener`] and [`router::RouterAsyncReqChannel`]
19-
//! instances to communicate over MCTP. Those implement the standard [`mctp` crate](mctp)
20-
//! async traits.
8+
//! This crate provides a MCTP stack and transport bindings,
9+
//! that can be embedded in other programs or devices.
2110
//!
2211
//! The IO-less [`Stack`] handles MCTP message formatting and parsing, independent
2312
//! of any particular MCTP transport binding.
2413
//!
14+
//! A Router for *async* applications is available
15+
//! through the `async` feature.
16+
//! The async `Router` lets programs use a `Stack`
17+
//! by providing implementations for the standard [`mctp` crate](mctp) async traits.
18+
//! Transport bindings are provided by *Ports* which handle transmitting and receiving
19+
//! packets independently. Messages destined for the stack's own EID will
20+
//! be passed to applications.
21+
//!
2522
//! ## Features
26-
//! - `embassy`: async `Router` for [Embassy](https://embassy.dev/)
27-
//! - `async`: [embedded-io-async](https://docs.rs/embedded-io-async/0.6.1/embedded_io_async/) serial transport binding (enabled by `embassy` feature)
23+
//! - `async`: [embedded-io-async](https://docs.rs/embedded-io-async/0.6.1/embedded_io_async/) serial transport binding and async Router
2824
//!
2925
//! ## Configuration
3026
//!
@@ -40,6 +36,7 @@
4036
// defmt does not currently allow inline format arguments, so we don't want
4137
// those reworked when using the log crate either.
4238
#![allow(clippy::uninlined_format_args)]
39+
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
4340

4441
#[cfg(test)]
4542
#[macro_use]
@@ -66,22 +63,22 @@ pub mod control;
6663
pub mod fragment;
6764
pub mod i2c;
6865
mod reassemble;
69-
#[cfg(feature = "embassy")]
66+
#[cfg(feature = "async")]
7067
pub mod router;
7168
pub mod serial;
7269
pub mod usb;
7370
#[macro_use]
7471
mod util;
7572
mod proto;
7673

77-
#[cfg(feature = "embassy")]
74+
#[cfg(feature = "async")]
7875
#[rustfmt::skip]
7976
#[allow(clippy::needless_lifetimes)]
8077
mod zerocopy_channel;
8178

8279
use fragment::{Fragmenter, SendOutput};
8380
use reassemble::Reassembler;
84-
#[cfg(feature = "embassy")]
81+
#[cfg(feature = "async")]
8582
pub use router::Router;
8683

8784
use crate::fmt::*;

mctp-estack/src/serial.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ use mctp::{Error, Result};
1212
use crc::Crc;
1313
use heapless::Vec;
1414

15-
#[cfg(feature = "embassy")]
15+
#[cfg(feature = "async")]
1616
use embedded_io_async::{Read, Write};
1717

18-
#[cfg(not(feature = "embassy"))]
18+
#[cfg(not(feature = "async"))]
1919
use embedded_io::{Read, Write};
2020

2121
const MCTP_SERIAL_REVISION: u8 = 0x01;
@@ -72,7 +72,7 @@ impl MctpSerialHandler {
7272
/// Read a frame.
7373
///
7474
/// This is async cancel-safe.
75-
#[cfg(feature = "embassy")]
75+
#[cfg(feature = "async")]
7676
pub async fn recv_async(&mut self, input: &mut impl Read) -> Result<&[u8]> {
7777
// TODO: This reads one byte a time, might need a buffering wrapper
7878
// for performance. Will require more thought about cancel-safety
@@ -103,7 +103,7 @@ impl MctpSerialHandler {
103103

104104
/// Read a frame synchronously.
105105
/// This function blocks until at least one byte is available
106-
#[cfg(not(feature = "embassy"))]
106+
#[cfg(not(feature = "async"))]
107107
pub fn recv(&mut self, input: &mut impl Read) -> Result<&[u8]> {
108108
// TODO: This reads one byte a time, might need a buffering wrapper
109109
// for performance. Will require more thought about cancel-safety
@@ -220,7 +220,7 @@ impl MctpSerialHandler {
220220
}
221221

222222
/// Asynchronously send a MCTP packet over serial provided by `output`.
223-
#[cfg(feature = "embassy")]
223+
#[cfg(feature = "async")]
224224
pub async fn send_async(
225225
&mut self,
226226
pkt: &[u8],
@@ -232,7 +232,7 @@ impl MctpSerialHandler {
232232
}
233233

234234
/// Synchronously send a MCTP packet over serial provided by `output`.
235-
#[cfg(not(feature = "embassy"))]
235+
#[cfg(not(feature = "async"))]
236236
pub fn send_sync(
237237
&mut self,
238238
pkt: &[u8],
@@ -242,7 +242,7 @@ impl MctpSerialHandler {
242242
}
243243

244244
/// Frame a MCTP packet into a serial frame, writing to `output`.
245-
#[cfg(feature = "embassy")]
245+
#[cfg(feature = "async")]
246246
async fn frame_to_serial<W>(
247247
p: &[u8],
248248
output: &mut W,
@@ -267,7 +267,7 @@ impl MctpSerialHandler {
267267
}
268268

269269
/// Frame a MCTP packet into a serial frame, writing to `output`.
270-
#[cfg(not(feature = "embassy"))]
270+
#[cfg(not(feature = "async"))]
271271
fn frame_to_serial<W>(
272272
p: &[u8],
273273
output: &mut W,
@@ -292,7 +292,7 @@ impl MctpSerialHandler {
292292
}
293293

294294
/// Asynchronously write a byte slice to `output`, escaping 0x7e and 0x7d bytes.
295-
#[cfg(feature = "embassy")]
295+
#[cfg(feature = "async")]
296296
async fn write_escaped<W>(
297297
p: &[u8],
298298
output: &mut W,
@@ -320,7 +320,7 @@ impl MctpSerialHandler {
320320
}
321321

322322
/// Synchronously write a byte slice to `output`, escaping 0x7e and 0x7d bytes.
323-
#[cfg(not(feature = "embassy"))]
323+
#[cfg(not(feature = "async"))]
324324
fn write_escaped<W>(
325325
p: &[u8],
326326
output: &mut W,
@@ -360,7 +360,7 @@ mod tests {
360360
use crate::*;
361361
use proptest::prelude::*;
362362

363-
#[cfg(feature = "embassy")]
363+
#[cfg(feature = "async")]
364364
use embedded_io_adapters::futures_03::FromFutures;
365365

366366
static TEST_DATA_ROUNTRIP: [&[u8]; 1] =
@@ -373,7 +373,7 @@ mod tests {
373373
.try_init();
374374
}
375375

376-
#[cfg(feature = "embassy")]
376+
#[cfg(feature = "async")]
377377
async fn do_roundtrip_async(payload: &[u8]) {
378378
let mut esc = vec![];
379379
let mut s = FromFutures::new(&mut esc);
@@ -391,7 +391,7 @@ mod tests {
391391
debug_assert_eq!(payload, packet);
392392
}
393393

394-
#[cfg(not(feature = "embassy"))]
394+
#[cfg(not(feature = "async"))]
395395
fn do_roundtrip_sync(payload: &[u8]) {
396396
start_log();
397397
let mut esc = vec![];
@@ -406,7 +406,7 @@ mod tests {
406406
debug_assert_eq!(payload, packet);
407407
}
408408

409-
#[cfg(feature = "embassy")]
409+
#[cfg(feature = "async")]
410410
#[test]
411411
fn roundtrip_cases_async() {
412412
// Fixed testcases
@@ -418,7 +418,7 @@ mod tests {
418418
})
419419
}
420420

421-
#[cfg(not(feature = "embassy"))]
421+
#[cfg(not(feature = "async"))]
422422
#[test]
423423
fn roundtrip_cases_sync() {
424424
start_log();
@@ -428,14 +428,14 @@ mod tests {
428428
}
429429

430430
proptest! {
431-
#[cfg(feature = "embassy")]
431+
#[cfg(feature = "async")]
432432
#[test]
433433
fn roundtrip_escape_async(payload in proptest::collection::vec(0..255u8, 5..20)) {
434434
start_log();
435435
smol::block_on(do_roundtrip_async(&payload))
436436
}
437437

438-
#[cfg(not(feature = "embassy"))]
438+
#[cfg(not(feature = "async"))]
439439
#[test]
440440
fn roundtrip_escape_sync(payload in proptest::collection::vec(0..255u8, 5..20)) {
441441
start_log();

mctp-estack/tests/roundtrip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Roundtrip heavily relies on the router implementation that we currently have
77
// to remove for a working synchronous implementaion.
88
// For now, exclude the entire roundtrip test.
9-
#![cfg(feature = "embassy")]
9+
#![cfg(feature = "async")]
1010

1111
#[allow(unused)]
1212
use log::{debug, error, info, trace, warn};

standalone/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ categories = ["network-programming"]
1010
[dependencies]
1111
embedded-io-async = { workspace = true }
1212
log = { workspace = true }
13-
mctp-estack = { workspace = true, default-features = true }
13+
mctp-estack = { workspace = true, default-features = true, features = ["async"] }
1414
mctp = { workspace = true }
1515
smol = { workspace = true }
1616

0 commit comments

Comments
 (0)