From 7174060ded24b97a0811fddbb67e6c7037b498a4 Mon Sep 17 00:00:00 2001 From: tison Date: Thu, 27 Aug 2026 00:28:02 +0800 Subject: [PATCH 1/2] refactor(channel): collect existing implementations --- asyncband/src/{mpsc => channel}/error.rs | 0 asyncband/src/channel/mod.rs | 24 +++++++++++++++++++ asyncband/src/{ => channel}/mpsc/bounded.rs | 8 +++---- asyncband/src/{ => channel}/mpsc/mod.rs | 10 ++++---- asyncband/src/{ => channel}/mpsc/unbounded.rs | 6 ++--- asyncband/src/{ => channel}/oneshot/mod.rs | 0 .../src/{ => channel}/oneshot/receiver.rs | 18 +++++++------- asyncband/src/{ => channel}/oneshot/sender.rs | 16 ++++++------- asyncband/src/{ => channel}/oneshot/tests.rs | 0 asyncband/src/lib.rs | 5 ++-- 10 files changed, 56 insertions(+), 31 deletions(-) rename asyncband/src/{mpsc => channel}/error.rs (100%) create mode 100644 asyncband/src/channel/mod.rs rename asyncband/src/{ => channel}/mpsc/bounded.rs (98%) rename asyncband/src/{ => channel}/mpsc/mod.rs (88%) rename asyncband/src/{ => channel}/mpsc/unbounded.rs (99%) rename asyncband/src/{ => channel}/oneshot/mod.rs (100%) rename asyncband/src/{ => channel}/oneshot/receiver.rs (98%) rename asyncband/src/{ => channel}/oneshot/sender.rs (97%) rename asyncband/src/{ => channel}/oneshot/tests.rs (100%) diff --git a/asyncband/src/mpsc/error.rs b/asyncband/src/channel/error.rs similarity index 100% rename from asyncband/src/mpsc/error.rs rename to asyncband/src/channel/error.rs diff --git a/asyncband/src/channel/mod.rs b/asyncband/src/channel/mod.rs new file mode 100644 index 0000000..87b7b9a --- /dev/null +++ b/asyncband/src/channel/mod.rs @@ -0,0 +1,24 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#[cfg(feature = "mpsc")] +mod error; + +#[cfg(feature = "mpsc")] +pub mod mpsc; +#[cfg(feature = "oneshot")] +pub mod oneshot; diff --git a/asyncband/src/mpsc/bounded.rs b/asyncband/src/channel/mpsc/bounded.rs similarity index 98% rename from asyncband/src/mpsc/bounded.rs rename to asyncband/src/channel/mpsc/bounded.rs index 60f0da0..08aefd4 100644 --- a/asyncband/src/mpsc/bounded.rs +++ b/asyncband/src/channel/mpsc/bounded.rs @@ -28,13 +28,13 @@ use std::sync::atomic::Ordering; use std::task::Context; use std::task::Poll; +use super::RecvError; +use super::SendError; +use super::TryRecvError; +use super::TrySendError; use crate::internal::atomic_waker::AtomicWaker; use crate::internal::semaphore::Acquire; use crate::internal::semaphore::Semaphore; -use crate::mpsc::RecvError; -use crate::mpsc::SendError; -use crate::mpsc::TryRecvError; -use crate::mpsc::error::TrySendError; /// Creates a bounded mpsc channel for communicating between asynchronous /// tasks with backpressure. diff --git a/asyncband/src/mpsc/mod.rs b/asyncband/src/channel/mpsc/mod.rs similarity index 88% rename from asyncband/src/mpsc/mod.rs rename to asyncband/src/channel/mpsc/mod.rs index 87c7c8f..2134bfc 100644 --- a/asyncband/src/mpsc/mod.rs +++ b/asyncband/src/channel/mpsc/mod.rs @@ -18,16 +18,16 @@ //! A multi-producer, single-consumer queue for sending values between asynchronous tasks. mod bounded; -mod error; mod unbounded; pub use bounded::BoundedReceiver; pub use bounded::BoundedSender; pub use bounded::bounded; -pub use error::RecvError; -pub use error::SendError; -pub use error::TryRecvError; -pub use error::TrySendError; pub use unbounded::UnboundedReceiver; pub use unbounded::UnboundedSender; pub use unbounded::unbounded; + +pub use super::error::RecvError; +pub use super::error::SendError; +pub use super::error::TryRecvError; +pub use super::error::TrySendError; diff --git a/asyncband/src/mpsc/unbounded.rs b/asyncband/src/channel/mpsc/unbounded.rs similarity index 99% rename from asyncband/src/mpsc/unbounded.rs rename to asyncband/src/channel/mpsc/unbounded.rs index eb446be..3ee892a 100644 --- a/asyncband/src/mpsc/unbounded.rs +++ b/asyncband/src/channel/mpsc/unbounded.rs @@ -26,10 +26,10 @@ use std::sync::atomic::Ordering; use std::task::Context; use std::task::Poll; +use super::RecvError; +use super::SendError; +use super::TryRecvError; use crate::internal::atomic_waker::AtomicWaker; -use crate::mpsc::RecvError; -use crate::mpsc::SendError; -use crate::mpsc::TryRecvError; /// Creates an unbounded mpsc channel for communicating between asynchronous /// tasks without backpressure. diff --git a/asyncband/src/oneshot/mod.rs b/asyncband/src/channel/oneshot/mod.rs similarity index 100% rename from asyncband/src/oneshot/mod.rs rename to asyncband/src/channel/oneshot/mod.rs diff --git a/asyncband/src/oneshot/receiver.rs b/asyncband/src/channel/oneshot/receiver.rs similarity index 98% rename from asyncband/src/oneshot/receiver.rs rename to asyncband/src/channel/oneshot/receiver.rs index 29f913b..7d232dc 100644 --- a/asyncband/src/oneshot/receiver.rs +++ b/asyncband/src/channel/oneshot/receiver.rs @@ -24,16 +24,16 @@ use std::sync::atomic::fence; use std::task::Context; use std::task::Poll; -use crate::oneshot::AWAKING; -use crate::oneshot::Channel; -use crate::oneshot::DISCONNECTED; -use crate::oneshot::EMPTY; -use crate::oneshot::MESSAGE; -use crate::oneshot::RECEIVING; +use super::AWAKING; +use super::Channel; +use super::DISCONNECTED; +use super::EMPTY; +use super::MESSAGE; +use super::RECEIVING; #[cfg(doc)] -use crate::oneshot::Sender; -use crate::oneshot::deallocate_empty_channel; -use crate::oneshot::drop_message_and_deallocate_channel; +use super::Sender; +use super::deallocate_empty_channel; +use super::drop_message_and_deallocate_channel; /// Receives a value from the associated [`Sender`]. pub struct Receiver { diff --git a/asyncband/src/oneshot/sender.rs b/asyncband/src/channel/oneshot/sender.rs similarity index 97% rename from asyncband/src/oneshot/sender.rs rename to asyncband/src/channel/oneshot/sender.rs index adf45ee..58a712c 100644 --- a/asyncband/src/oneshot/sender.rs +++ b/asyncband/src/channel/oneshot/sender.rs @@ -22,15 +22,15 @@ use std::ptr::NonNull; use std::sync::atomic::Ordering; use std::sync::atomic::fence; -use crate::oneshot::Channel; -use crate::oneshot::DISCONNECTED; -use crate::oneshot::EMPTY; -use crate::oneshot::MESSAGE; -use crate::oneshot::RECEIVING; +use super::Channel; +use super::DISCONNECTED; +use super::EMPTY; +use super::MESSAGE; +use super::RECEIVING; #[cfg(doc)] -use crate::oneshot::Receiver; -use crate::oneshot::deallocate_empty_channel; -use crate::oneshot::drop_message_and_deallocate_channel; +use super::Receiver; +use super::deallocate_empty_channel; +use super::drop_message_and_deallocate_channel; /// Sends a value to the associated [`Receiver`]. pub struct Sender { diff --git a/asyncband/src/oneshot/tests.rs b/asyncband/src/channel/oneshot/tests.rs similarity index 100% rename from asyncband/src/oneshot/tests.rs rename to asyncband/src/channel/oneshot/tests.rs diff --git a/asyncband/src/lib.rs b/asyncband/src/lib.rs index 41a52d8..733275a 100644 --- a/asyncband/src/lib.rs +++ b/asyncband/src/lib.rs @@ -100,6 +100,7 @@ //! //! While incubation status is not necessarily a reflection of the completeness or stability of the //! code, it does indicate that the project has yet to be fully endorsed by the ASF. +mod channel; mod internal; #[cfg(feature = "barrier")] @@ -111,7 +112,7 @@ pub mod condvar; #[cfg(feature = "latch")] pub mod latch; #[cfg(feature = "mpsc")] -pub mod mpsc; +pub use self::channel::mpsc; #[cfg(feature = "mutex")] pub mod mutex; #[cfg(any( @@ -122,7 +123,7 @@ pub mod mutex; ))] pub mod once; #[cfg(feature = "oneshot")] -pub mod oneshot; +pub use self::channel::oneshot; #[cfg(feature = "pool")] pub mod pool; #[cfg(feature = "rwlock")] From 706b57ae46e1f9d2776f1b5de997a788be9a0d02 Mon Sep 17 00:00:00 2001 From: tison Date: Thu, 27 Aug 2026 00:33:10 +0800 Subject: [PATCH 2/2] refactor(mpsc): keep errors local --- asyncband/src/channel/mod.rs | 3 --- asyncband/src/channel/{ => mpsc}/error.rs | 0 asyncband/src/channel/mpsc/mod.rs | 10 +++++----- 3 files changed, 5 insertions(+), 8 deletions(-) rename asyncband/src/channel/{ => mpsc}/error.rs (100%) diff --git a/asyncband/src/channel/mod.rs b/asyncband/src/channel/mod.rs index 87b7b9a..58689a6 100644 --- a/asyncband/src/channel/mod.rs +++ b/asyncband/src/channel/mod.rs @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -#[cfg(feature = "mpsc")] -mod error; - #[cfg(feature = "mpsc")] pub mod mpsc; #[cfg(feature = "oneshot")] diff --git a/asyncband/src/channel/error.rs b/asyncband/src/channel/mpsc/error.rs similarity index 100% rename from asyncband/src/channel/error.rs rename to asyncband/src/channel/mpsc/error.rs diff --git a/asyncband/src/channel/mpsc/mod.rs b/asyncband/src/channel/mpsc/mod.rs index 2134bfc..87c7c8f 100644 --- a/asyncband/src/channel/mpsc/mod.rs +++ b/asyncband/src/channel/mpsc/mod.rs @@ -18,16 +18,16 @@ //! A multi-producer, single-consumer queue for sending values between asynchronous tasks. mod bounded; +mod error; mod unbounded; pub use bounded::BoundedReceiver; pub use bounded::BoundedSender; pub use bounded::bounded; +pub use error::RecvError; +pub use error::SendError; +pub use error::TryRecvError; +pub use error::TrySendError; pub use unbounded::UnboundedReceiver; pub use unbounded::UnboundedSender; pub use unbounded::unbounded; - -pub use super::error::RecvError; -pub use super::error::SendError; -pub use super::error::TryRecvError; -pub use super::error::TrySendError;