Skip to content

Commit 974b109

Browse files
feat(runtime): add compile-time check for mutually exclusive features
Add compile_error! checks to prevent both `tokio` and `smol` features from being enabled simultaneously in libp2p-swarm, libp2p-tcp, and libp2p-quic crates. This follows Cargo's recommended approach for handling mutually exclusive features as documented in: https://doc.rust-lang.org/cargo/reference/features.html#mutually-exclusive-features 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 3722955 commit 974b109

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

swarm/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@
5353
5454
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
5555

56+
// Ensure `tokio` and `smol` features are not enabled at the same time.
57+
// See: https://doc.rust-lang.org/cargo/reference/features.html#mutually-exclusive-features
58+
#[cfg(all(feature = "tokio", feature = "smol"))]
59+
compile_error!(
60+
"features `tokio` and `smol` are mutually exclusive; \
61+
please enable only one async runtime feature"
62+
);
63+
5664
mod connection;
5765
mod executor;
5866
mod stream;

transports/quic/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@
6060
6161
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
6262

63+
// Ensure `tokio` and `smol` features are not enabled at the same time.
64+
// See: https://doc.rust-lang.org/cargo/reference/features.html#mutually-exclusive-features
65+
#[cfg(all(feature = "tokio", feature = "smol"))]
66+
compile_error!(
67+
"features `tokio` and `smol` are mutually exclusive; \
68+
please enable only one async runtime feature"
69+
);
70+
6371
mod config;
6472
mod connection;
6573
mod hole_punching;

transports/tcp/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@
2828
2929
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
3030

31+
// Ensure `tokio` and `smol` features are not enabled at the same time.
32+
// See: https://doc.rust-lang.org/cargo/reference/features.html#mutually-exclusive-features
33+
#[cfg(all(feature = "tokio", feature = "smol"))]
34+
compile_error!(
35+
"features `tokio` and `smol` are mutually exclusive; \
36+
please enable only one async runtime feature"
37+
);
38+
3139
mod provider;
3240

3341
use std::{

0 commit comments

Comments
 (0)