From 7ed41a9d187a8a4f0df2f3e6659559fbd084a5db Mon Sep 17 00:00:00 2001 From: Zachary Dremann Date: Tue, 7 May 2024 22:27:01 -0400 Subject: [PATCH 1/2] Add the ability to construct `StaticChannel`s with a recycle --- src/mpsc/async_impl.rs | 18 ++++++++++++++---- src/mpsc/blocking.rs | 17 ++++++++++++++--- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/mpsc/async_impl.rs b/src/mpsc/async_impl.rs index 9f410d2..5a2f7ff 100644 --- a/src/mpsc/async_impl.rs +++ b/src/mpsc/async_impl.rs @@ -936,16 +936,26 @@ feature! { /// [`split`]: StaticChannel::split #[must_use] pub const fn new() -> Self { + Self::with_recycle(recycling::DefaultRecycle::new()) + } + } + + impl StaticChannel { + /// Constructs a new statically-allocated, asynchronous bounded MPSC channel + /// with the provided [recycling policy]. + /// + /// See [`Self::new`] for more information. + /// + /// [recycling policy]: crate::recycling::Recycle + #[must_use] + pub const fn with_recycle(recycle: R) -> Self { Self { core: ChannelCore::new(CAPACITY), slots: Slot::make_static_array::(), is_split: AtomicBool::new(false), - recycle: recycling::DefaultRecycle::new(), + recycle, } } - } - - impl StaticChannel { /// Split a [`StaticChannel`] into a [`StaticSender`]/[`StaticReceiver`] /// pair. /// diff --git a/src/mpsc/blocking.rs b/src/mpsc/blocking.rs index 49a8aed..36db3ca 100644 --- a/src/mpsc/blocking.rs +++ b/src/mpsc/blocking.rs @@ -196,16 +196,27 @@ feature! { /// [`split`]: StaticChannel::split #[must_use] pub const fn new() -> Self { + Self::with_recycle(recycling::DefaultRecycle::new()) + } + } + + impl StaticChannel { + /// Constructs a new statically-allocated, blocking bounded MPSC channel + /// with the provided [recycling policy]. + /// + /// See [`Self::new`] for more information. + /// + /// [recycling policy]: crate::recycling::Recycle + #[must_use] + pub const fn with_recycle(recycle: R) -> Self { Self { core: ChannelCore::new(CAPACITY), slots: Slot::make_static_array::(), is_split: AtomicBool::new(false), - recycle: recycling::DefaultRecycle::new(), + recycle, } } - } - impl StaticChannel { /// Split a [`StaticChannel`] into a [`StaticSender`]/[`StaticReceiver`] /// pair. /// From cc7e99e285cd4c37ac646c8ac7a6a29facae01e4 Mon Sep 17 00:00:00 2001 From: Zachary Dremann Date: Mon, 27 May 2024 22:25:42 -0400 Subject: [PATCH 2/2] Tell Rust about our used cfgs --- Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 426f967..bb013ae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,3 +53,6 @@ loom = { git = "https://github.com/tokio-rs/loom", rev = "a93bf2390e0fcfdb7c5899 [package.metadata.docs.rs] all-features = true rustdoc-args = ["--cfg", "docsrs"] + +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(loom)', 'cfg(thingbuf_trace)'] }