From bfc83af83bc759efb6dba7b1c3af24153da7606a Mon Sep 17 00:00:00 2001 From: tison Date: Sun, 11 Oct 2026 11:55:44 +0100 Subject: [PATCH 1/8] style: standardize imports across the workspace --- asyncband/src/blocking/executor.rs | 2 +- asyncband/src/broadcast/mpmc/bounded/mod.rs | 12 +-- asyncband/src/broadcast/mpmc/common.rs | 6 +- asyncband/src/broadcast/mpmc/error.rs | 7 +- asyncband/src/broadcast/mpmc/mod.rs | 18 ++--- asyncband/src/broadcast/mpmc/unbounded/mod.rs | 12 +-- asyncband/src/completion/mod.rs | 3 +- asyncband/src/event/auto_reset.rs | 4 +- asyncband/src/event/mod.rs | 4 +- asyncband/src/internal/arena.rs | 5 +- asyncband/src/internal/mutex.rs | 8 +- asyncband/src/internal/waker_batch.rs | 2 +- asyncband/src/internal/wakerset.rs | 2 +- asyncband/src/mpmc/bounded.rs | 16 ++-- asyncband/src/mpmc/error.rs | 9 ++- asyncband/src/mpmc/mod.rs | 22 +++--- asyncband/src/mpmc/queue.rs | 8 +- asyncband/src/mpmc/unbounded.rs | 10 +-- asyncband/src/mpsc/bounded/mod.rs | 6 +- asyncband/src/mpsc/bounded/receiver.rs | 2 +- asyncband/src/mpsc/bounded/sender.rs | 8 +- asyncband/src/mpsc/error.rs | 9 ++- asyncband/src/mpsc/mod.rs | 22 +++--- asyncband/src/mpsc/unbounded/buffer.rs | 9 ++- asyncband/src/mpsc/unbounded/mod.rs | 6 +- asyncband/src/mpsc/unbounded/receiver.rs | 6 +- asyncband/src/mpsc/unbounded/sender.rs | 2 +- asyncband/src/mutex/mod.rs | 15 ++-- asyncband/src/once/lazy_cell/mod.rs | 13 +++- asyncband/src/once/mod.rs | 8 +- asyncband/src/once/once_map/tests.rs | 15 ++-- asyncband/src/oneshot/mod.rs | 12 +-- asyncband/src/oneshot/receiver.rs | 5 +- asyncband/src/oneshot/sender.rs | 3 +- asyncband/src/oneshot/tests.rs | 5 +- asyncband/src/phaser/mod.rs | 3 +- asyncband/src/phaser/tests.rs | 2 +- asyncband/src/pool/bounded.rs | 16 ++-- asyncband/src/pool/mod.rs | 17 +++-- asyncband/src/pool/unbounded.rs | 36 +++++---- asyncband/src/rwlock/access.rs | 5 +- asyncband/src/rwlock/mod.rs | 16 ++-- asyncband/src/rwlock/owned_read_guard.rs | 5 +- asyncband/src/semaphore/mod.rs | 3 +- asyncband/src/shutdown/mod.rs | 12 ++- asyncband/src/singleflight/mod.rs | 10 ++- asyncband/src/singleflight/tests.rs | 5 +- asyncband/src/spmc/bounded.rs | 10 +-- asyncband/src/spmc/error.rs | 9 ++- asyncband/src/spmc/mod.rs | 40 ++++++---- asyncband/src/spmc/queue.rs | 8 +- asyncband/src/spmc/unbounded.rs | 10 +-- asyncband/src/watch/error.rs | 5 +- asyncband/src/watch/mod.rs | 4 +- asyncband/src/watch/tests.rs | 4 +- .../ecosystem/broadcast/mpmc/adapters.rs | 31 ++++---- .../ecosystem/broadcast/mpmc/bounded.rs | 26 ++++--- .../broadcast/mpmc/no_backpressure.rs | 20 ++--- .../ecosystem/broadcast/mpmc/support.rs | 9 ++- benchmarks/benches/ecosystem/mpsc/adapters.rs | 26 ++++--- benchmarks/benches/ecosystem/mpsc/bounded.rs | 28 +++---- .../benches/ecosystem/mpsc/reservation.rs | 22 +++--- benchmarks/benches/ecosystem/mpsc/support.rs | 34 +++++---- .../benches/ecosystem/mpsc/unbounded.rs | 36 ++++----- benchmarks/benches/ecosystem/waitgroup.rs | 7 +- .../benches/ecosystem/watch/adapters.rs | 15 ++-- benchmarks/benches/ecosystem/watch/paths.rs | 6 +- benchmarks/benches/primitives/mpmc/bounded.rs | 2 +- .../benches/primitives/mpmc/unbounded.rs | 2 +- .../benches/primitives/once_map/initialize.rs | 12 +-- .../benches/primitives/once_map/lookup.rs | 14 ++-- .../primitives/once_map/maintenance.rs | 10 +-- .../primitives/singleflight/coalescing.rs | 6 +- .../primitives/singleflight/leaders.rs | 14 ++-- benchmarks/src/channels/adapters.rs | 28 +++---- benchmarks/src/channels/mod.rs | 7 +- benchmarks/src/channels/mpmc.rs | 13 ++-- benchmarks/src/channels/spmc.rs | 9 ++- examples/src/coalesced_worker.rs | 3 +- examples/src/graceful_shutdown.rs | 8 +- examples/src/lazy_cell_boxed_vs_inline.rs | 6 +- examples/src/notify_vs_event.rs | 5 +- examples/src/once_cell_vs_lazy_cell.rs | 3 +- examples/src/phaser_completion.rs | 3 +- examples/src/phaser_rounds.rs | 7 +- examples/src/shared_completion.rs | 9 ++- tests-integration/src/lib.rs | 16 ++-- tests-integration/tests/blocking_test.rs | 20 ++--- .../tests/broadcast_test/bounded.rs | 13 ++-- .../tests/broadcast_test/unbounded.rs | 6 +- tests-integration/tests/completion_test.rs | 7 +- tests-integration/tests/condvar_test.rs | 3 +- tests-integration/tests/latch_test.rs | 3 +- tests-integration/tests/lazy_cell_test.rs | 26 ++++--- .../tests/mpmc_test/concurrency.rs | 5 +- .../tests/mpmc_test/notification.rs | 4 +- .../tests/mpsc_test/callbacks.rs | 7 +- .../tests/mpsc_test/concurrency.rs | 25 ++++--- .../tests/mpsc_test/reservation.rs | 9 ++- tests-integration/tests/mutex_test.rs | 12 ++- tests-integration/tests/once_cell_test.rs | 6 +- tests-integration/tests/once_map_test.rs | 7 +- tests-integration/tests/once_test.rs | 6 +- tests-integration/tests/oneshot_test/main.rs | 8 +- .../tests/oneshot_test/support.rs | 7 +- tests-integration/tests/phaser_test.rs | 14 ++-- tests-integration/tests/pool_test/acquire.rs | 9 ++- tests-integration/tests/pool_test/behavior.rs | 2 +- tests-integration/tests/pool_test/recycle.rs | 6 +- .../tests/pool_test/replenish.rs | 6 +- tests-integration/tests/rwlock_test.rs | 17 +++-- tests-integration/tests/semaphore_test.rs | 8 +- tests-integration/tests/shutdown_test.rs | 3 +- tests-integration/tests/singleflight_test.rs | 13 ++-- .../tests/spmc_test/concurrency.rs | 3 +- .../tests/spmc_test/notification.rs | 2 +- tests-integration/tests/traits_test.rs | 73 ++++++++++--------- tests-integration/tests/watch_test.rs | 6 +- xtask/src/main.rs | 5 +- 119 files changed, 719 insertions(+), 575 deletions(-) diff --git a/asyncband/src/blocking/executor.rs b/asyncband/src/blocking/executor.rs index 0a9c1e2a..8bebf8fc 100644 --- a/asyncband/src/blocking/executor.rs +++ b/asyncband/src/blocking/executor.rs @@ -16,7 +16,7 @@ use std::task::Waker; use std::time::Duration; use std::time::Instant; -use super::parker::Parker; +use crate::blocking::parker::Parker; pub(super) fn block_on(future: F) -> F::Output { let mut future = pin!(future.into_future()); diff --git a/asyncband/src/broadcast/mpmc/bounded/mod.rs b/asyncband/src/broadcast/mpmc/bounded/mod.rs index 0bfbc8b5..43735ed1 100644 --- a/asyncband/src/broadcast/mpmc/bounded/mod.rs +++ b/asyncband/src/broadcast/mpmc/bounded/mod.rs @@ -109,12 +109,12 @@ use std::sync::atomic::Ordering; use std::task::Context; use std::task::Poll; -use super::common; -use super::common::Backlog; -use super::common::Inner; -use super::error::RecvError; -use super::error::TryRecvError; -use super::error::TrySendError; +use crate::broadcast::mpmc::common; +use crate::broadcast::mpmc::common::Backlog; +use crate::broadcast::mpmc::common::Inner; +use crate::broadcast::mpmc::error::RecvError; +use crate::broadcast::mpmc::error::TryRecvError; +use crate::broadcast::mpmc::error::TrySendError; use crate::internal::arena::SlotId; use crate::internal::mutex::Mutex; use crate::internal::semaphore::Acquire; diff --git a/asyncband/src/broadcast/mpmc/common.rs b/asyncband/src/broadcast/mpmc/common.rs index 74a04a9a..15cb1978 100644 --- a/asyncband/src/broadcast/mpmc/common.rs +++ b/asyncband/src/broadcast/mpmc/common.rs @@ -32,8 +32,8 @@ use std::sync::atomic::Ordering; use std::task::Context; use std::task::Poll; -use super::error::RecvError; -use super::error::TryRecvError; +use crate::broadcast::mpmc::error::RecvError; +use crate::broadcast::mpmc::error::TryRecvError; use crate::internal::arena::Arena; use crate::internal::arena::SlotId; use crate::internal::mutex::Mutex; @@ -533,7 +533,7 @@ pub fn take_msg(msg: Arc, reclaimed: Reclaimed) -> T { mod tests { use std::sync::Arc; - use super::Backlog; + use crate::broadcast::mpmc::common::Backlog; /// Drives every cursor-count mutation point — subscribing, publishing, receiving, and dropping /// — and checks the accounting after each step. diff --git a/asyncband/src/broadcast/mpmc/error.rs b/asyncband/src/broadcast/mpmc/error.rs index f1cbce93..28f21726 100644 --- a/asyncband/src/broadcast/mpmc/error.rs +++ b/asyncband/src/broadcast/mpmc/error.rs @@ -16,6 +16,7 @@ // under the License. use std::any::type_name; +use std::error::Error; use std::fmt; /// Error returned by [`BoundedSender::try_send`]. @@ -65,7 +66,7 @@ impl fmt::Debug for TrySendError { } } -impl std::error::Error for TrySendError {} +impl Error for TrySendError {} /// Error returned by `recv`. #[derive(Debug, Clone, PartialEq, Eq)] @@ -80,7 +81,7 @@ impl fmt::Display for RecvError { } } -impl std::error::Error for RecvError {} +impl Error for RecvError {} /// Error returned by `try_recv`. #[derive(Debug, Clone, PartialEq, Eq)] @@ -100,4 +101,4 @@ impl fmt::Display for TryRecvError { } } -impl std::error::Error for TryRecvError {} +impl Error for TryRecvError {} diff --git a/asyncband/src/broadcast/mpmc/mod.rs b/asyncband/src/broadcast/mpmc/mod.rs index b5eb4afd..dcd502d7 100644 --- a/asyncband/src/broadcast/mpmc/mod.rs +++ b/asyncband/src/broadcast/mpmc/mod.rs @@ -43,12 +43,12 @@ mod common; mod error; mod unbounded; -pub use self::bounded::BoundedReceiver; -pub use self::bounded::BoundedSender; -pub use self::bounded::bounded; -pub use self::error::RecvError; -pub use self::error::TryRecvError; -pub use self::error::TrySendError; -pub use self::unbounded::UnboundedReceiver; -pub use self::unbounded::UnboundedSender; -pub use self::unbounded::unbounded; +pub use crate::broadcast::mpmc::bounded::BoundedReceiver; +pub use crate::broadcast::mpmc::bounded::BoundedSender; +pub use crate::broadcast::mpmc::bounded::bounded; +pub use crate::broadcast::mpmc::error::RecvError; +pub use crate::broadcast::mpmc::error::TryRecvError; +pub use crate::broadcast::mpmc::error::TrySendError; +pub use crate::broadcast::mpmc::unbounded::UnboundedReceiver; +pub use crate::broadcast::mpmc::unbounded::UnboundedSender; +pub use crate::broadcast::mpmc::unbounded::unbounded; diff --git a/asyncband/src/broadcast/mpmc/unbounded/mod.rs b/asyncband/src/broadcast/mpmc/unbounded/mod.rs index de2eab06..044796d5 100644 --- a/asyncband/src/broadcast/mpmc/unbounded/mod.rs +++ b/asyncband/src/broadcast/mpmc/unbounded/mod.rs @@ -52,7 +52,7 @@ //! assert_eq!(late.try_recv(), Err(TryRecvError::Empty)); //! ``` //! -//! [`bounded`]: super::bounded +//! [`bounded`]: crate::broadcast::mpmc::bounded use std::fmt; use std::future::Future; @@ -63,11 +63,11 @@ use std::sync::atomic::Ordering; use std::task::Context; use std::task::Poll; -use super::common; -use super::common::Backlog; -use super::common::Inner; -use super::error::RecvError; -use super::error::TryRecvError; +use crate::broadcast::mpmc::common; +use crate::broadcast::mpmc::common::Backlog; +use crate::broadcast::mpmc::common::Inner; +use crate::broadcast::mpmc::error::RecvError; +use crate::broadcast::mpmc::error::TryRecvError; use crate::internal::arena::SlotId; use crate::internal::mutex::Mutex; use crate::internal::wakerset::WakerToken; diff --git a/asyncband/src/completion/mod.rs b/asyncband/src/completion/mod.rs index 95ce3c15..923e80be 100644 --- a/asyncband/src/completion/mod.rs +++ b/asyncband/src/completion/mod.rs @@ -48,6 +48,7 @@ //! # } //! ``` +use std::error::Error; use std::fmt; use std::future::Future; use std::mem; @@ -91,7 +92,7 @@ impl fmt::Display for Abandoned { } } -impl std::error::Error for Abandoned {} +impl Error for Abandoned {} /// The capability that completes a [`Completion`] with one value. /// diff --git a/asyncband/src/event/auto_reset.rs b/asyncband/src/event/auto_reset.rs index 3bbe5ca2..9e6107f5 100644 --- a/asyncband/src/event/auto_reset.rs +++ b/asyncband/src/event/auto_reset.rs @@ -37,8 +37,8 @@ use crate::internal::waitlist::WaiterId; /// An unassigned signal can be cleared with [`reset`](Self::reset). /// /// Waiting consumes a signal without returning it on completion. Unlike a -/// [`ManualResetEvent`](super::ManualResetEvent), this event does not release all observers of a -/// condition. Unlike a semaphore, it does not count unused signals or return a permit guard. +/// [`ManualResetEvent`](crate::event::ManualResetEvent), this event does not release all observers +/// of a condition. Unlike a semaphore, it does not count unused signals or return a permit guard. /// /// # Usage /// diff --git a/asyncband/src/event/mod.rs b/asyncband/src/event/mod.rs index 8f94320f..5372f905 100644 --- a/asyncband/src/event/mod.rs +++ b/asyncband/src/event/mod.rs @@ -31,5 +31,5 @@ mod auto_reset; mod manual_reset; -pub use self::auto_reset::AutoResetEvent; -pub use self::manual_reset::ManualResetEvent; +pub use crate::event::auto_reset::AutoResetEvent; +pub use crate::event::manual_reset::ManualResetEvent; diff --git a/asyncband/src/internal/arena.rs b/asyncband/src/internal/arena.rs index 68a6b4e1..2c33b5fc 100644 --- a/asyncband/src/internal/arena.rs +++ b/asyncband/src/internal/arena.rs @@ -15,6 +15,7 @@ // specific language governing permissions and limitations // under the License. +use std::fmt; use std::mem; use std::num::NonZeroUsize; @@ -41,8 +42,8 @@ impl SlotId { } } -impl std::fmt::Debug for SlotId { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Debug for SlotId { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("SlotId").field(&self.index()).finish() } } diff --git a/asyncband/src/internal/mutex.rs b/asyncband/src/internal/mutex.rs index 93baf8f2..24cd5bf7 100644 --- a/asyncband/src/internal/mutex.rs +++ b/asyncband/src/internal/mutex.rs @@ -16,9 +16,11 @@ // under the License. use std::fmt; +use std::sync::Mutex as StdMutex; +use std::sync::MutexGuard; use std::sync::PoisonError; -pub struct Mutex(std::sync::Mutex); +pub struct Mutex(StdMutex); impl fmt::Debug for Mutex { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -28,10 +30,10 @@ impl fmt::Debug for Mutex { impl Mutex { pub const fn new(t: T) -> Self { - Self(std::sync::Mutex::new(t)) + Self(StdMutex::new(t)) } - pub fn lock(&self) -> std::sync::MutexGuard<'_, T> { + pub fn lock(&self) -> MutexGuard<'_, T> { self.0.lock().unwrap_or_else(PoisonError::into_inner) } diff --git a/asyncband/src/internal/waker_batch.rs b/asyncband/src/internal/waker_batch.rs index ff9c0e81..25b22391 100644 --- a/asyncband/src/internal/waker_batch.rs +++ b/asyncband/src/internal/waker_batch.rs @@ -109,7 +109,7 @@ mod tests { use std::task::Wake; use std::task::Waker; - use super::WakerBatch; + use crate::internal::waker_batch::WakerBatch; const STACK_SIZE: usize = WakerBatch::STACK_SIZE; diff --git a/asyncband/src/internal/wakerset.rs b/asyncband/src/internal/wakerset.rs index cbd3ff0e..a909b6c8 100644 --- a/asyncband/src/internal/wakerset.rs +++ b/asyncband/src/internal/wakerset.rs @@ -111,7 +111,7 @@ impl WakerSet { #[cfg(test)] mod tests { - use super::WakerToken; + use crate::internal::wakerset::WakerToken; #[test] fn waker_token_preserves_the_option_niche() { diff --git a/asyncband/src/mpmc/bounded.rs b/asyncband/src/mpmc/bounded.rs index 31dc1d9b..c3f0bf6a 100644 --- a/asyncband/src/mpmc/bounded.rs +++ b/asyncband/src/mpmc/bounded.rs @@ -18,12 +18,12 @@ use std::fmt; use std::sync::Arc; -use super::RecvError; -use super::SendError; -use super::TryRecvError; -use super::TrySendError; -pub use super::queue::Permit; -use super::queue::Shared; +use crate::mpmc::RecvError; +use crate::mpmc::SendError; +use crate::mpmc::TryRecvError; +use crate::mpmc::TrySendError; +pub use crate::mpmc::queue::Permit; +use crate::mpmc::queue::Shared; /// Creates a bounded multi-producer, multi-consumer queue. /// @@ -108,7 +108,9 @@ impl BoundedSender { /// ``` /// # #[tokio::main] /// # async fn main() { - /// let (sender, receiver) = asyncband::mpmc::bounded(1); + /// use asyncband::mpmc; + /// + /// let (sender, receiver) = mpmc::bounded(1); /// let permit = sender.reserve().await.unwrap(); /// let message = String::from("constructed after capacity became available"); /// permit.send(message).unwrap(); diff --git a/asyncband/src/mpmc/error.rs b/asyncband/src/mpmc/error.rs index 200f013e..06bfcf89 100644 --- a/asyncband/src/mpmc/error.rs +++ b/asyncband/src/mpmc/error.rs @@ -16,6 +16,7 @@ // under the License. use std::any::type_name; +use std::error::Error; use std::fmt; /// An error returned when trying to send on a disconnected queue. @@ -52,7 +53,7 @@ impl fmt::Debug for SendError { } } -impl std::error::Error for SendError {} +impl Error for SendError {} /// Error returned by [`BoundedSender::try_send`](crate::mpmc::BoundedSender::try_send) or /// [`BoundedSender::try_reserve`](crate::mpmc::BoundedSender::try_reserve). @@ -101,7 +102,7 @@ impl fmt::Debug for TrySendError { } } -impl std::error::Error for TrySendError {} +impl Error for TrySendError {} /// Error returned when receiving a value fails. #[derive(Debug, Clone, PartialEq, Eq)] @@ -116,7 +117,7 @@ impl fmt::Display for RecvError { } } -impl std::error::Error for RecvError {} +impl Error for RecvError {} /// Error returned by a non-blocking attempt to receive a value. #[derive(Debug, Clone, PartialEq, Eq)] @@ -136,4 +137,4 @@ impl fmt::Display for TryRecvError { } } -impl std::error::Error for TryRecvError {} +impl Error for TryRecvError {} diff --git a/asyncband/src/mpmc/mod.rs b/asyncband/src/mpmc/mod.rs index ebb03a0c..86daf1f3 100644 --- a/asyncband/src/mpmc/mod.rs +++ b/asyncband/src/mpmc/mod.rs @@ -27,14 +27,14 @@ mod error; mod queue; mod unbounded; -pub use self::bounded::BoundedReceiver; -pub use self::bounded::BoundedSender; -pub use self::bounded::Permit; -pub use self::bounded::bounded; -pub use self::error::RecvError; -pub use self::error::SendError; -pub use self::error::TryRecvError; -pub use self::error::TrySendError; -pub use self::unbounded::UnboundedReceiver; -pub use self::unbounded::UnboundedSender; -pub use self::unbounded::unbounded; +pub use crate::mpmc::bounded::BoundedReceiver; +pub use crate::mpmc::bounded::BoundedSender; +pub use crate::mpmc::bounded::Permit; +pub use crate::mpmc::bounded::bounded; +pub use crate::mpmc::error::RecvError; +pub use crate::mpmc::error::SendError; +pub use crate::mpmc::error::TryRecvError; +pub use crate::mpmc::error::TrySendError; +pub use crate::mpmc::unbounded::UnboundedReceiver; +pub use crate::mpmc::unbounded::UnboundedSender; +pub use crate::mpmc::unbounded::unbounded; diff --git a/asyncband/src/mpmc/queue.rs b/asyncband/src/mpmc/queue.rs index 211bab46..02bb9d7a 100644 --- a/asyncband/src/mpmc/queue.rs +++ b/asyncband/src/mpmc/queue.rs @@ -23,13 +23,13 @@ use std::task::Context; use std::task::Poll; use std::task::Waker; -use super::RecvError; -use super::SendError; -use super::TryRecvError; -use super::TrySendError; use crate::internal::mutex::Mutex; use crate::internal::waitlist::WaitList; use crate::internal::waitlist::WaiterId; +use crate::mpmc::RecvError; +use crate::mpmc::SendError; +use crate::mpmc::TryRecvError; +use crate::mpmc::TrySendError; pub struct Shared { state: Mutex>, diff --git a/asyncband/src/mpmc/unbounded.rs b/asyncband/src/mpmc/unbounded.rs index 20bf3591..1a9e6bc8 100644 --- a/asyncband/src/mpmc/unbounded.rs +++ b/asyncband/src/mpmc/unbounded.rs @@ -18,11 +18,11 @@ use std::fmt; use std::sync::Arc; -use super::RecvError; -use super::SendError; -use super::TryRecvError; -use super::TrySendError; -use super::queue::Shared; +use crate::mpmc::RecvError; +use crate::mpmc::SendError; +use crate::mpmc::TryRecvError; +use crate::mpmc::TrySendError; +use crate::mpmc::queue::Shared; /// Creates an unbounded multi-producer, multi-consumer queue. /// diff --git a/asyncband/src/mpsc/bounded/mod.rs b/asyncband/src/mpsc/bounded/mod.rs index a1e5abfc..962c8d25 100644 --- a/asyncband/src/mpsc/bounded/mod.rs +++ b/asyncband/src/mpsc/bounded/mod.rs @@ -30,9 +30,9 @@ use crate::mpsc::TrySendError; mod receiver; mod sender; -pub use self::receiver::BoundedReceiver; -pub use self::sender::BoundedSender; -pub use self::sender::Permit; +pub use crate::mpsc::bounded::receiver::BoundedReceiver; +pub use crate::mpsc::bounded::sender::BoundedSender; +pub use crate::mpsc::bounded::sender::Permit; /// Creates a bounded mpsc channel with room for `buffer` queued messages. /// diff --git a/asyncband/src/mpsc/bounded/receiver.rs b/asyncband/src/mpsc/bounded/receiver.rs index bd4f6110..2d37f898 100644 --- a/asyncband/src/mpsc/bounded/receiver.rs +++ b/asyncband/src/mpsc/bounded/receiver.rs @@ -22,12 +22,12 @@ use std::sync::Arc; use std::task::Context; use std::task::Poll; -use super::State; use crate::internal::mutex::Mutex; use crate::internal::register_waker; use crate::internal::waitlist::WaitList; use crate::mpsc::RecvError; use crate::mpsc::TryRecvError; +use crate::mpsc::bounded::State; /// The receiving endpoint of a bounded mpsc channel. /// diff --git a/asyncband/src/mpsc/bounded/sender.rs b/asyncband/src/mpsc/bounded/sender.rs index 586ec9c1..f90f99bd 100644 --- a/asyncband/src/mpsc/bounded/sender.rs +++ b/asyncband/src/mpsc/bounded/sender.rs @@ -22,13 +22,13 @@ use std::sync::Arc; use std::task::Context; use std::task::Poll; -use super::State; -use super::Waiter; use crate::internal::mutex::Mutex; use crate::internal::register_waker; use crate::internal::waitlist::WaiterId; use crate::mpsc::SendError; use crate::mpsc::TrySendError; +use crate::mpsc::bounded::State; +use crate::mpsc::bounded::Waiter; /// The sending endpoint of a bounded mpsc channel. /// @@ -117,7 +117,9 @@ impl BoundedSender { /// ``` /// # #[tokio::main] /// # async fn main() { - /// let (tx, mut rx) = asyncband::mpsc::bounded(1); + /// use asyncband::mpsc; + /// + /// let (tx, mut rx) = mpsc::bounded(1); /// let permit = tx.reserve().await.unwrap(); /// let message = String::from("constructed after capacity became available"); /// permit.send(message).unwrap(); diff --git a/asyncband/src/mpsc/error.rs b/asyncband/src/mpsc/error.rs index 9737e2f2..e55d801a 100644 --- a/asyncband/src/mpsc/error.rs +++ b/asyncband/src/mpsc/error.rs @@ -16,6 +16,7 @@ // under the License. use std::any::type_name; +use std::error::Error; use std::fmt; /// An attempt to send a message or reserve capacity failed because the receiver has been dropped. @@ -63,7 +64,7 @@ impl fmt::Debug for SendError { } } -impl std::error::Error for SendError {} +impl Error for SendError {} /// An attempt to send or reserve capacity failed. /// @@ -114,7 +115,7 @@ impl fmt::Debug for TrySendError { } } -impl std::error::Error for TrySendError {} +impl Error for TrySendError {} /// An attempt to receive a value failed because the channel is disconnected. #[derive(Debug, Clone, PartialEq, Eq)] @@ -129,7 +130,7 @@ impl fmt::Display for RecvError { } } -impl std::error::Error for RecvError {} +impl Error for RecvError {} /// A non-blocking attempt to receive a value failed. #[derive(Debug, Clone, PartialEq, Eq)] @@ -149,4 +150,4 @@ impl fmt::Display for TryRecvError { } } -impl std::error::Error for TryRecvError {} +impl Error for TryRecvError {} diff --git a/asyncband/src/mpsc/mod.rs b/asyncband/src/mpsc/mod.rs index bad23f06..21e623b5 100644 --- a/asyncband/src/mpsc/mod.rs +++ b/asyncband/src/mpsc/mod.rs @@ -25,14 +25,14 @@ mod bounded; mod error; mod unbounded; -pub use self::bounded::BoundedReceiver; -pub use self::bounded::BoundedSender; -pub use self::bounded::Permit; -pub use self::bounded::bounded; -pub use self::error::RecvError; -pub use self::error::SendError; -pub use self::error::TryRecvError; -pub use self::error::TrySendError; -pub use self::unbounded::UnboundedReceiver; -pub use self::unbounded::UnboundedSender; -pub use self::unbounded::unbounded; +pub use crate::mpsc::bounded::BoundedReceiver; +pub use crate::mpsc::bounded::BoundedSender; +pub use crate::mpsc::bounded::Permit; +pub use crate::mpsc::bounded::bounded; +pub use crate::mpsc::error::RecvError; +pub use crate::mpsc::error::SendError; +pub use crate::mpsc::error::TryRecvError; +pub use crate::mpsc::error::TrySendError; +pub use crate::mpsc::unbounded::UnboundedReceiver; +pub use crate::mpsc::unbounded::UnboundedSender; +pub use crate::mpsc::unbounded::unbounded; diff --git a/asyncband/src/mpsc/unbounded/buffer.rs b/asyncband/src/mpsc/unbounded/buffer.rs index 371bb2a4..0a1a81b4 100644 --- a/asyncband/src/mpsc/unbounded/buffer.rs +++ b/asyncband/src/mpsc/unbounded/buffer.rs @@ -99,10 +99,11 @@ pub fn pop_batch(batch: &mut VecDeque) -> T { #[cfg(test)] mod tests { use std::collections::VecDeque; + use std::iter::once; - use super::Buffer; - use super::SEGMENT_BYTES; - use super::pop_batch; + use crate::mpsc::unbounded::buffer::Buffer; + use crate::mpsc::unbounded::buffer::SEGMENT_BYTES; + use crate::mpsc::unbounded::buffer::pop_batch; fn allocated_bytes(buffer: &Buffer, batch: &VecDeque) -> usize { let slots = batch.capacity() @@ -149,7 +150,7 @@ mod tests { for _ in 0..2 { for value in 0..messages { buffer.push([value as u8; SIZE]); - for segment in std::iter::once(&buffer.writable).chain(&buffer.sealed) { + for segment in once(&buffer.writable).chain(&buffer.sealed) { assert!(segment.capacity() * SIZE <= SEGMENT_BYTES); } } diff --git a/asyncband/src/mpsc/unbounded/mod.rs b/asyncband/src/mpsc/unbounded/mod.rs index 4955c27e..23f2284a 100644 --- a/asyncband/src/mpsc/unbounded/mod.rs +++ b/asyncband/src/mpsc/unbounded/mod.rs @@ -21,15 +21,15 @@ use std::sync::Arc; use std::task::Waker; -use self::buffer::Buffer; use crate::internal::mutex::Mutex; +use crate::mpsc::unbounded::buffer::Buffer; mod buffer; mod receiver; mod sender; -pub use self::receiver::UnboundedReceiver; -pub use self::sender::UnboundedSender; +pub use crate::mpsc::unbounded::receiver::UnboundedReceiver; +pub use crate::mpsc::unbounded::sender::UnboundedSender; /// Creates an unbounded mpsc channel. Sending never waits for capacity. /// diff --git a/asyncband/src/mpsc/unbounded/receiver.rs b/asyncband/src/mpsc/unbounded/receiver.rs index 6874b4c2..6e7009de 100644 --- a/asyncband/src/mpsc/unbounded/receiver.rs +++ b/asyncband/src/mpsc/unbounded/receiver.rs @@ -23,13 +23,13 @@ use std::sync::Arc; use std::task::Context; use std::task::Poll; -use super::State; -use super::buffer::Buffer; -use super::buffer::pop_batch; use crate::internal::mutex::Mutex; use crate::internal::register_waker; use crate::mpsc::RecvError; use crate::mpsc::TryRecvError; +use crate::mpsc::unbounded::State; +use crate::mpsc::unbounded::buffer::Buffer; +use crate::mpsc::unbounded::buffer::pop_batch; /// The receiving endpoint of an unbounded mpsc channel. /// diff --git a/asyncband/src/mpsc/unbounded/sender.rs b/asyncband/src/mpsc/unbounded/sender.rs index a90589c5..ab353031 100644 --- a/asyncband/src/mpsc/unbounded/sender.rs +++ b/asyncband/src/mpsc/unbounded/sender.rs @@ -18,9 +18,9 @@ use std::fmt; use std::sync::Arc; -use super::State; use crate::internal::mutex::Mutex; use crate::mpsc::SendError; +use crate::mpsc::unbounded::State; /// The sending endpoint of an unbounded mpsc channel. /// diff --git a/asyncband/src/mutex/mod.rs b/asyncband/src/mutex/mod.rs index ffed4559..5469d492 100644 --- a/asyncband/src/mutex/mod.rs +++ b/asyncband/src/mutex/mod.rs @@ -69,6 +69,7 @@ use std::marker::PhantomData; use std::mem::ManuallyDrop; use std::ops::Deref; use std::ops::DerefMut; +use std::ptr; use std::ptr::NonNull; use std::sync::Arc; @@ -372,17 +373,19 @@ impl<'a, T: ?Sized> MutexGuard<'a, T> { /// ``` /// # #[tokio::main] /// # async fn main() { + /// use std::collections::HashMap; + /// /// use asyncband::mutex::Mutex; /// use asyncband::mutex::MutexGuard; /// /// #[derive(Debug)] /// struct Database { - /// users: std::collections::HashMap, + /// users: HashMap, /// admin_user_id: Option, /// } /// /// let mut db = Database { - /// users: std::collections::HashMap::new(), + /// users: HashMap::new(), /// admin_user_id: Some(1), /// }; /// db.users.insert(1, "admin@example.com".to_owned()); @@ -516,7 +519,7 @@ impl OwnedMutexGuard { // SAFETY: The guard is wrapped in `ManuallyDrop` and will not be dropped, // so the `Arc` can be moved out to transfer lock ownership to the new guard. - let lock = unsafe { std::ptr::read(&guard.lock) }; + let lock = unsafe { ptr::read(&guard.lock) }; OwnedMappedMutexGuard { lock, @@ -563,7 +566,7 @@ impl OwnedMutexGuard { // SAFETY: The guard is wrapped in `ManuallyDrop` and will not be dropped, // so the `Arc` can be moved out to transfer lock ownership to the new guard. - let lock = unsafe { std::ptr::read(&guard.lock) }; + let lock = unsafe { ptr::read(&guard.lock) }; Ok(OwnedMappedMutexGuard { lock, @@ -920,7 +923,7 @@ impl OwnedMappedMutexGuard { // SAFETY: The guard is wrapped in `ManuallyDrop` and will not be dropped, // so the `Arc` can be moved out to transfer lock ownership to the new guard. - let lock = unsafe { std::ptr::read(&orig.lock) }; + let lock = unsafe { ptr::read(&orig.lock) }; OwnedMappedMutexGuard { lock, @@ -989,7 +992,7 @@ impl OwnedMappedMutexGuard { // SAFETY: The guard is wrapped in `ManuallyDrop` and will not be dropped, // so the `Arc` can be moved out to transfer lock ownership to the new guard. - let lock = unsafe { std::ptr::read(&orig.lock) }; + let lock = unsafe { ptr::read(&orig.lock) }; Ok(OwnedMappedMutexGuard { lock, diff --git a/asyncband/src/once/lazy_cell/mod.rs b/asyncband/src/once/lazy_cell/mod.rs index 25c49528..a0418765 100644 --- a/asyncband/src/once/lazy_cell/mod.rs +++ b/asyncband/src/once/lazy_cell/mod.rs @@ -19,11 +19,14 @@ use std::fmt; use std::future::Future; use std::future::Pending; use std::future::Ready; +use std::future::poll_fn; +use std::future::ready; use std::panic::RefUnwindSafe; use std::panic::UnwindSafe; use std::pin::Pin; use std::sync::atomic::AtomicBool; use std::sync::atomic::Ordering; +use std::thread; use crate::internal::value_cell::ValueCell; use crate::mutex::Mutex; @@ -131,10 +134,12 @@ impl LazyCell { /// ``` /// # #[tokio::main] /// # async fn main() { + /// use std::pin::pin; + /// /// use asyncband::once::LazyCell; /// /// let lazy = LazyCell::new(async || 92); - /// let lazy = std::pin::pin!(lazy); + /// let lazy = pin!(lazy); /// assert_eq!(*LazyCell::force_pin(lazy.as_ref()).await, 92); /// # } /// ``` @@ -372,7 +377,7 @@ where *unsafe { state.as_mut().get_unchecked_mut() } = State::Attempt(future); } - let value = std::future::poll_fn(|cx| { + let value = poll_fn(|cx| { let _poison = PoisonOnPanic(poisoned); // SAFETY: The state remains pinned while this future is polled, and the attempt is never // moved after it is installed. @@ -401,7 +406,7 @@ where { fn default() -> Self { fn initialize() -> Ready { - std::future::ready(T::default()) + ready(T::default()) } Self::new(initialize::) @@ -464,7 +469,7 @@ struct PoisonOnPanic<'a>(&'a AtomicBool); impl Drop for PoisonOnPanic<'_> { fn drop(&mut self) { - if std::thread::panicking() { + if thread::panicking() { self.0.store(true, Ordering::Relaxed); } } diff --git a/asyncband/src/once/mod.rs b/asyncband/src/once/mod.rs index 770d538d..3a814966 100644 --- a/asyncband/src/once/mod.rs +++ b/asyncband/src/once/mod.rs @@ -41,10 +41,10 @@ mod once_cell; mod once_map; #[cfg(feature = "lazy-cell")] -pub use self::lazy_cell::LazyCell; +pub use crate::once::lazy_cell::LazyCell; #[cfg(feature = "once")] -pub use self::once::Once; +pub use crate::once::once::Once; #[cfg(feature = "once-cell")] -pub use self::once_cell::OnceCell; +pub use crate::once::once_cell::OnceCell; #[cfg(feature = "once-map")] -pub use self::once_map::OnceMap; +pub use crate::once::once_map::OnceMap; diff --git a/asyncband/src/once/once_map/tests.rs b/asyncband/src/once/once_map/tests.rs index fe25d1cf..53a14d73 100644 --- a/asyncband/src/once/once_map/tests.rs +++ b/asyncband/src/once/once_map/tests.rs @@ -16,6 +16,7 @@ // under the License. use std::cell::Cell; +use std::future::pending; use std::future::poll_fn; use std::hash::BuildHasherDefault; use std::hash::Hasher; @@ -25,8 +26,8 @@ use std::pin::pin; use std::sync::Arc; use std::task::Poll; -use super::Lookup; -use super::OnceMap; +use crate::once::once_map::Lookup; +use crate::once::once_map::OnceMap; use crate::test_support::poll_once; // These tests stay next to the implementation because they inspect private state. @@ -78,7 +79,7 @@ fn cancelled_compute_removes_empty_entry() { let map = OnceMap::<&str, i32>::new(); { - let mut compute = pin!(map.compute("key", async || std::future::pending::().await)); + let mut compute = pin!(map.compute("key", async || pending::().await)); assert!(poll_once(compute.as_mut()).is_pending()); assert_eq!(map.len(), 1); } @@ -90,13 +91,11 @@ fn cancelled_compute_removes_empty_entry() { fn pending_computation_does_not_block_another_key() { let map = OnceMap::new(); { - let mut pending = std::pin::pin!( - map.compute("pending", async || { std::future::pending::().await }) - ); + let mut pending = pin!(map.compute("pending", async || { pending::().await })); assert!(poll_once(pending.as_mut()).is_pending()); - let mut ready = std::pin::pin!(map.compute("ready", async || 1)); - assert_eq!(poll_once(ready.as_mut()), std::task::Poll::Ready(1)); + let mut ready = pin!(map.compute("ready", async || 1)); + assert_eq!(poll_once(ready.as_mut()), Poll::Ready(1)); } assert_eq!(map.len(), 1); diff --git a/asyncband/src/oneshot/mod.rs b/asyncband/src/oneshot/mod.rs index 7859d7bc..f53242ab 100644 --- a/asyncband/src/oneshot/mod.rs +++ b/asyncband/src/oneshot/mod.rs @@ -99,12 +99,12 @@ use std::sync::atomic::fence; use std::task::Poll; use std::task::Waker; -pub use self::receiver::Receiver; -pub use self::receiver::Recv; -pub use self::receiver::RecvError; -pub use self::receiver::TryRecvError; -pub use self::sender::SendError; -pub use self::sender::Sender; +pub use crate::oneshot::receiver::Receiver; +pub use crate::oneshot::receiver::Recv; +pub use crate::oneshot::receiver::RecvError; +pub use crate::oneshot::receiver::TryRecvError; +pub use crate::oneshot::sender::SendError; +pub use crate::oneshot::sender::Sender; #[cfg(test)] mod tests; diff --git a/asyncband/src/oneshot/receiver.rs b/asyncband/src/oneshot/receiver.rs index 9f0228b3..abe7279d 100644 --- a/asyncband/src/oneshot/receiver.rs +++ b/asyncband/src/oneshot/receiver.rs @@ -22,6 +22,7 @@ // https://github.com/faern/oneshot/blob/25274e995ee0a702b3e9e1ac81e577f8c3ce0892/src/lib.rs // https://github.com/faern/oneshot/blob/25274e995ee0a702b3e9e1ac81e577f8c3ce0892/src/errors.rs +use std::error::Error; use std::fmt; use std::mem::ManuallyDrop; use std::pin::Pin; @@ -420,7 +421,7 @@ impl fmt::Display for TryRecvError { } } -impl std::error::Error for TryRecvError {} +impl Error for TryRecvError {} /// An error returned when awaiting the message via [`Receiver`]. /// @@ -440,4 +441,4 @@ impl fmt::Display for RecvError { } } -impl std::error::Error for RecvError {} +impl Error for RecvError {} diff --git a/asyncband/src/oneshot/sender.rs b/asyncband/src/oneshot/sender.rs index 738c4dda..74d004bf 100644 --- a/asyncband/src/oneshot/sender.rs +++ b/asyncband/src/oneshot/sender.rs @@ -23,6 +23,7 @@ // https://github.com/faern/oneshot/blob/25274e995ee0a702b3e9e1ac81e577f8c3ce0892/src/errors.rs use std::any::type_name; +use std::error::Error; use std::fmt; use std::mem::ManuallyDrop; use std::ptr::NonNull; @@ -275,7 +276,7 @@ impl fmt::Debug for SendError { } } -impl std::error::Error for SendError {} +impl Error for SendError {} #[cfg(test)] impl Sender { diff --git a/asyncband/src/oneshot/tests.rs b/asyncband/src/oneshot/tests.rs index 4e293261..7763986d 100644 --- a/asyncband/src/oneshot/tests.rs +++ b/asyncband/src/oneshot/tests.rs @@ -177,6 +177,7 @@ mod support { use std::sync::atomic::Ordering; use std::task::Wake; use std::task::Waker; + use std::thread; pub(super) struct DropProbe { drop_count: Arc, @@ -234,12 +235,12 @@ mod support { } } - pub(super) fn spawn_named(name: &str, f: F) -> std::thread::JoinHandle + pub(super) fn spawn_named(name: &str, f: F) -> thread::JoinHandle where F: FnOnce() -> T + Send + 'static, T: Send + 'static, { - std::thread::Builder::new() + thread::Builder::new() .name(name.to_owned()) .spawn(f) .unwrap() diff --git a/asyncband/src/phaser/mod.rs b/asyncband/src/phaser/mod.rs index b96cba5f..60c0f40e 100644 --- a/asyncband/src/phaser/mod.rs +++ b/asyncband/src/phaser/mod.rs @@ -121,6 +121,7 @@ //! from the same phaser to `wait`; it tests for a different phase, not a target number //! or numeric threshold. An observation must not be retained across a full counter cycle. +use std::error::Error; use std::fmt; use std::future::Future; use std::iter::FusedIterator; @@ -150,7 +151,7 @@ impl fmt::Display for Closed { } } -impl std::error::Error for Closed {} +impl Error for Closed {} /// A shared handle to a reusable phase barrier with dynamic participants. /// diff --git a/asyncband/src/phaser/tests.rs b/asyncband/src/phaser/tests.rs index 48cffa89..f644cf83 100644 --- a/asyncband/src/phaser/tests.rs +++ b/asyncband/src/phaser/tests.rs @@ -17,7 +17,7 @@ use std::task::Poll; -use super::Phaser; +use crate::phaser::Phaser; use crate::test_support::poll_once; #[test] diff --git a/asyncband/src/pool/bounded.rs b/asyncband/src/pool/bounded.rs index 9b3e2fd5..947435a5 100644 --- a/asyncband/src/pool/bounded.rs +++ b/asyncband/src/pool/bounded.rs @@ -73,6 +73,7 @@ //! # } //! ``` +use std::fmt; use std::ops::Deref; use std::ops::DerefMut; use std::sync::Arc; @@ -164,12 +165,12 @@ pub struct Pool { slots: Mutex>, } -impl std::fmt::Debug for Pool +impl fmt::Debug for Pool where M: ManageObject, - M::Object: std::fmt::Debug, + M::Object: fmt::Debug, { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Pool") .field("slots", &self.slots) .field("config", &self.config) @@ -336,6 +337,7 @@ impl Pool { /// # use asyncband::pool::ObjectStatus; /// # use asyncband::pool::bounded::Pool; /// # use asyncband::pool::bounded::PoolConfig; + /// use tokio::time::sleep; /// let interval = Duration::from_secs(30); /// let max_age = Duration::from_secs(60); /// @@ -360,7 +362,7 @@ impl Pool { /// let weak_pool = Arc::downgrade(&pool); /// tokio::spawn(async move { /// loop { - /// tokio::time::sleep(interval).await; + /// sleep(interval).await; /// if let Some(pool) = weak_pool.upgrade() { /// pool.retain(|_, status| status.last_used().elapsed() < max_age); /// } else { @@ -476,12 +478,12 @@ pub struct Object { pool: Weak>, } -impl std::fmt::Debug for Object +impl fmt::Debug for Object where M: ManageObject, - M::Object: std::fmt::Debug, + M::Object: fmt::Debug, { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Object") .field("state", &self.state) .field("permit", &self.permit) diff --git a/asyncband/src/pool/mod.rs b/asyncband/src/pool/mod.rs index 8895e941..afa6e77e 100644 --- a/asyncband/src/pool/mod.rs +++ b/asyncband/src/pool/mod.rs @@ -124,6 +124,7 @@ //! use asyncband::pool::bounded::Object; //! use asyncband::pool::bounded::Pool; //! # use asyncband::pool::bounded::PoolConfig; +//! use tokio::time::timeout; //! //! # struct Connection; //! # #[derive(Debug)] @@ -160,7 +161,7 @@ //! const ACQUIRE_TIMEOUT: Duration = Duration::from_secs(60); //! //! // Callers can use the timer implementation of their runtime. -//! match tokio::time::timeout(ACQUIRE_TIMEOUT, self.pool.get()).await { +//! match timeout(ACQUIRE_TIMEOUT, self.pool.get()).await { //! Ok(result) => result.map_err(AcquireError::Create), //! Err(_) => Err(AcquireError::Timeout), //! } @@ -180,13 +181,15 @@ //! For example, create and recycle behavior can be expressed directly by [`ManageObject`]: //! //! ``` +//! use std::convert::Infallible; +//! //! use asyncband::pool::ManageObject; //! use asyncband::pool::ObjectStatus; //! //! struct Manager; //! impl ManageObject for Manager { //! type Object = i32; -//! type Error = std::convert::Infallible; +//! type Error = Infallible; //! //! async fn create(&self) -> Result { //! let o = 42; @@ -211,8 +214,8 @@ mod state; pub mod bounded; pub mod unbounded; -pub use self::common::ManageObject; -pub use self::common::ObjectStatus; -pub use self::common::QueueStrategy; -pub use self::common::RecycleCancelledStrategy; -pub use self::common::RetainResult; +pub use crate::pool::common::ManageObject; +pub use crate::pool::common::ObjectStatus; +pub use crate::pool::common::QueueStrategy; +pub use crate::pool::common::RecycleCancelledStrategy; +pub use crate::pool::common::RetainResult; diff --git a/asyncband/src/pool/unbounded.rs b/asyncband/src/pool/unbounded.rs index 6f7337ce..a9a66757 100644 --- a/asyncband/src/pool/unbounded.rs +++ b/asyncband/src/pool/unbounded.rs @@ -88,7 +88,10 @@ //! # } //! ``` +use std::error::Error; +use std::fmt; use std::future::Future; +use std::future::ready; use std::marker::PhantomData; use std::ops::Deref; use std::ops::DerefMut; @@ -180,8 +183,8 @@ impl Clone for NeverManageObject { } } -impl std::fmt::Debug for NeverManageObject { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Debug for NeverManageObject { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("NeverManageObject") } } @@ -197,26 +200,26 @@ impl Default for NeverManageObject { /// The error returned by [`NeverManageObject::create`]. pub struct PoolIsEmpty(()); -impl std::fmt::Debug for PoolIsEmpty { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Debug for PoolIsEmpty { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("unbounded pool is empty") } } -impl std::fmt::Display for PoolIsEmpty { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Display for PoolIsEmpty { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("unbounded pool is empty") } } -impl std::error::Error for PoolIsEmpty {} +impl Error for PoolIsEmpty {} impl ManageObject for NeverManageObject { type Object = T; type Error = PoolIsEmpty; fn create(&self) -> impl Future> + Send { - std::future::ready(Err(PoolIsEmpty(()))) + ready(Err(PoolIsEmpty(()))) } fn is_recyclable( @@ -224,7 +227,7 @@ impl ManageObject for NeverManageObject { _: &mut Self::Object, _: &ObjectStatus, ) -> impl Future> + Send { - std::future::ready(Ok(())) + ready(Ok(())) } } @@ -239,12 +242,12 @@ pub struct Pool = NeverManageObject> { slots: Mutex>, } -impl std::fmt::Debug for Pool +impl fmt::Debug for Pool where - T: std::fmt::Debug, + T: fmt::Debug, M: ManageObject, { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Pool") .field("slots", &self.slots) .field("config", &self.config) @@ -423,6 +426,7 @@ impl> Pool { /// # use std::time::Duration; /// # use asyncband::pool::unbounded::Pool; /// # use asyncband::pool::unbounded::PoolConfig; + /// use tokio::time::sleep; /// let interval = Duration::from_secs(30); /// let max_age = Duration::from_secs(60); /// @@ -430,7 +434,7 @@ impl> Pool { /// let weak_pool = Arc::downgrade(&pool); /// tokio::spawn(async move { /// loop { - /// tokio::time::sleep(interval).await; + /// sleep(interval).await; /// if let Some(pool) = weak_pool.upgrade() { /// pool.retain(|_, status| status.last_used().elapsed() < max_age); /// } else { @@ -492,12 +496,12 @@ pub struct Object = NeverManageObject> { pool: Weak>, } -impl std::fmt::Debug for Object +impl fmt::Debug for Object where - T: std::fmt::Debug, + T: fmt::Debug, M: ManageObject, { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Object") .field("state", &self.state) .finish() diff --git a/asyncband/src/rwlock/access.rs b/asyncband/src/rwlock/access.rs index fd9637e4..1e92587b 100644 --- a/asyncband/src/rwlock/access.rs +++ b/asyncband/src/rwlock/access.rs @@ -20,6 +20,7 @@ //! Guards hold a token instead of implementing `Drop`, so projecting or downgrading a guard moves //! the token into the new guard. +use std::mem; use std::sync::Arc; use crate::internal::semaphore::Semaphore; @@ -72,7 +73,7 @@ impl<'a, T: ?Sized> ReadAccess<&'a RwLock> { let lock = self.owner; // The new token takes over releasing the permit; forgetting this one avoids releasing it // during the transfer. Its borrowed owner needs no cleanup. - std::mem::forget(self); + mem::forget(self); ReadAccess::new(&lock.s) } } @@ -119,7 +120,7 @@ impl<'a, T: ?Sized> WriteAccess<&'a RwLock> { let permits_acquired = self.permits_acquired; // The new token takes over releasing the permits; forgetting this one avoids releasing them // during the transfer. Its borrowed owner needs no cleanup. - std::mem::forget(self); + mem::forget(self); WriteAccess::new(&lock.s, permits_acquired) } } diff --git a/asyncband/src/rwlock/mod.rs b/asyncband/src/rwlock/mod.rs index a806d036..4e032710 100644 --- a/asyncband/src/rwlock/mod.rs +++ b/asyncband/src/rwlock/mod.rs @@ -116,14 +116,14 @@ mod owned_write_guard; mod read_guard; mod write_guard; -pub use self::mapped_read_guard::MappedRwLockReadGuard; -pub use self::mapped_write_guard::MappedRwLockWriteGuard; -pub use self::owned_mapped_read_guard::OwnedMappedRwLockReadGuard; -pub use self::owned_mapped_write_guard::OwnedMappedRwLockWriteGuard; -pub use self::owned_read_guard::OwnedRwLockReadGuard; -pub use self::owned_write_guard::OwnedRwLockWriteGuard; -pub use self::read_guard::RwLockReadGuard; -pub use self::write_guard::RwLockWriteGuard; +pub use crate::rwlock::mapped_read_guard::MappedRwLockReadGuard; +pub use crate::rwlock::mapped_write_guard::MappedRwLockWriteGuard; +pub use crate::rwlock::owned_mapped_read_guard::OwnedMappedRwLockReadGuard; +pub use crate::rwlock::owned_mapped_write_guard::OwnedMappedRwLockWriteGuard; +pub use crate::rwlock::owned_read_guard::OwnedRwLockReadGuard; +pub use crate::rwlock::owned_write_guard::OwnedRwLockWriteGuard; +pub use crate::rwlock::read_guard::RwLockReadGuard; +pub use crate::rwlock::write_guard::RwLockWriteGuard; /// A value with fair, asynchronous shared or exclusive access. /// diff --git a/asyncband/src/rwlock/owned_read_guard.rs b/asyncband/src/rwlock/owned_read_guard.rs index 7424c70e..8eb4a62e 100644 --- a/asyncband/src/rwlock/owned_read_guard.rs +++ b/asyncband/src/rwlock/owned_read_guard.rs @@ -24,6 +24,7 @@ use std::fmt; use std::ops::Deref; +use std::ptr::NonNull; use std::sync::Arc; use crate::rwlock::OwnedMappedRwLockReadGuard; @@ -101,7 +102,7 @@ impl OwnedRwLockReadGuard { F: FnOnce(&T) -> &U, U: ?Sized, { - let d = std::ptr::NonNull::from(f(&*orig)); + let d = NonNull::from(f(&*orig)); OwnedMappedRwLockReadGuard::new(d, orig.access) } @@ -117,7 +118,7 @@ impl OwnedRwLockReadGuard { { match f(&*orig) { Some(d) => { - let d = std::ptr::NonNull::from(d); + let d = NonNull::from(d); Ok(OwnedMappedRwLockReadGuard::new(d, orig.access)) } None => Err(orig), diff --git a/asyncband/src/semaphore/mod.rs b/asyncband/src/semaphore/mod.rs index 876742cd..93340e31 100644 --- a/asyncband/src/semaphore/mod.rs +++ b/asyncband/src/semaphore/mod.rs @@ -51,6 +51,7 @@ //! # } //! ``` +use std::ptr; use std::sync::Arc; use crate::internal::semaphore; @@ -399,7 +400,7 @@ impl SemaphorePermit<'_> { #[track_caller] pub fn merge(&mut self, mut other: Self) { assert!( - std::ptr::eq(self.sem, other.sem), + ptr::eq(self.sem, other.sem), "merging permits from different semaphore instances" ); self.permits = self diff --git a/asyncband/src/shutdown/mod.rs b/asyncband/src/shutdown/mod.rs index f5307500..8dcaab22 100644 --- a/asyncband/src/shutdown/mod.rs +++ b/asyncband/src/shutdown/mod.rs @@ -38,7 +38,9 @@ //! ``` //! # #[tokio::main] //! # async fn main() { -//! let (shutdown, guard) = asyncband::shutdown::new(); +//! use asyncband::shutdown; +//! +//! let (shutdown, guard) = shutdown::new(); //! let mut tasks = vec![]; //! //! for _ in 0..3 { @@ -101,7 +103,11 @@ pub fn new() -> (Shutdown, ShutdownGuard) { /// ``` /// # #[tokio::main] /// # async fn main() { -/// let (shutdown, guard) = asyncband::shutdown::new(); +/// use std::future::pending; +/// +/// use asyncband::shutdown; +/// +/// let (shutdown, guard) = shutdown::new(); /// let worker = tokio::spawn(async move { /// guard.shutdown_requested().await; /// }); @@ -110,7 +116,7 @@ pub fn new() -> (Shutdown, ShutdownGuard) { /// /// tokio::select! { /// _ = shutdown => {} -/// _ = std::future::pending::<()>() => {} +/// _ = pending::<()>() => {} /// } /// /// worker.await.unwrap(); diff --git a/asyncband/src/singleflight/mod.rs b/asyncband/src/singleflight/mod.rs index 104193ac..f3470a4a 100644 --- a/asyncband/src/singleflight/mod.rs +++ b/asyncband/src/singleflight/mod.rs @@ -253,6 +253,7 @@ where /// use std::time::Duration; /// /// use asyncband::singleflight::Group; + /// use tokio::time::sleep; /// /// # #[tokio::main] /// # async fn main() { @@ -263,7 +264,7 @@ where /// let fut1 = group.work("key", || async move { /// c1.fetch_add(1, Ordering::SeqCst); /// // simulate heavy work to avoid immediate completion - /// tokio::time::sleep(Duration::from_millis(100)).await; + /// sleep(Duration::from_millis(100)).await; /// "result" /// }); /// @@ -271,7 +272,7 @@ where /// let fut2 = group.work("key", || async move { /// c2.fetch_add(1, Ordering::SeqCst); /// // simulate heavy work to avoid immediate completion - /// tokio::time::sleep(Duration::from_millis(100)).await; + /// sleep(Duration::from_millis(100)).await; /// "result" /// }); /// @@ -328,6 +329,7 @@ where /// use std::time::Duration; /// /// use asyncband::singleflight::Group; + /// use tokio::time::sleep; /// /// # #[tokio::main] /// # async fn main() { @@ -335,13 +337,13 @@ where /// /// let fut1 = group.try_work("key", || async move { /// // simulate heavy work to avoid immediate completion - /// tokio::time::sleep(Duration::from_millis(100)).await; + /// sleep(Duration::from_millis(100)).await; /// Err::<_, &'static str>("fut1") /// }); /// /// let fut2 = group.try_work("key", || async move { /// // simulate heavy work to avoid immediate completion - /// tokio::time::sleep(Duration::from_millis(200)).await; + /// sleep(Duration::from_millis(200)).await; /// Ok::<_, &'static str>("fut2") /// }); /// diff --git a/asyncband/src/singleflight/tests.rs b/asyncband/src/singleflight/tests.rs index 123bfa43..aa0c3f4b 100644 --- a/asyncband/src/singleflight/tests.rs +++ b/asyncband/src/singleflight/tests.rs @@ -16,13 +16,14 @@ // under the License. use std::cell::Cell; +use std::future::pending; use std::future::poll_fn; use std::panic::AssertUnwindSafe; use std::panic::catch_unwind; use std::pin::pin; use std::task::Poll; -use super::Group; +use crate::singleflight::Group; use crate::test_support::poll_once; // These tests stay next to the implementation because they inspect private state. @@ -54,7 +55,7 @@ fn cancelled_work_removes_empty_entry() { let group = Group::<&str, &str>::new(); { - let mut work = pin!(group.work("key", || async { std::future::pending::<&str>().await })); + let mut work = pin!(group.work("key", || async { pending::<&str>().await })); assert!(poll_once(work.as_mut()).is_pending()); assert_eq!(entry_count(&group), 1); } diff --git a/asyncband/src/spmc/bounded.rs b/asyncband/src/spmc/bounded.rs index b4d7e529..fad902a3 100644 --- a/asyncband/src/spmc/bounded.rs +++ b/asyncband/src/spmc/bounded.rs @@ -18,11 +18,11 @@ use std::fmt; use std::sync::Arc; -use super::RecvError; -use super::SendError; -use super::TryRecvError; -use super::TrySendError; -use super::queue::Shared; +use crate::spmc::RecvError; +use crate::spmc::SendError; +use crate::spmc::TryRecvError; +use crate::spmc::TrySendError; +use crate::spmc::queue::Shared; /// Creates a bounded single-producer, multi-consumer queue. /// diff --git a/asyncband/src/spmc/error.rs b/asyncband/src/spmc/error.rs index fe63ad2a..09a680dc 100644 --- a/asyncband/src/spmc/error.rs +++ b/asyncband/src/spmc/error.rs @@ -16,6 +16,7 @@ // under the License. use std::any::type_name; +use std::error::Error; use std::fmt; /// An error returned when trying to send on a disconnected queue. @@ -52,7 +53,7 @@ impl fmt::Debug for SendError { } } -impl std::error::Error for SendError {} +impl Error for SendError {} /// Error returned by [`BoundedSender::try_send`](crate::spmc::BoundedSender::try_send). #[derive(Clone, PartialEq, Eq)] @@ -100,7 +101,7 @@ impl fmt::Debug for TrySendError { } } -impl std::error::Error for TrySendError {} +impl Error for TrySendError {} /// Error returned when receiving a value fails. #[derive(Debug, Clone, PartialEq, Eq)] @@ -115,7 +116,7 @@ impl fmt::Display for RecvError { } } -impl std::error::Error for RecvError {} +impl Error for RecvError {} /// Error returned by a non-blocking attempt to receive a value. #[derive(Debug, Clone, PartialEq, Eq)] @@ -135,4 +136,4 @@ impl fmt::Display for TryRecvError { } } -impl std::error::Error for TryRecvError {} +impl Error for TryRecvError {} diff --git a/asyncband/src/spmc/mod.rs b/asyncband/src/spmc/mod.rs index dd79fbe9..5604b4b9 100644 --- a/asyncband/src/spmc/mod.rs +++ b/asyncband/src/spmc/mod.rs @@ -52,25 +52,33 @@ //! Neither sender supports cloning: //! //! ```compile_fail,E0599 -//! let (sender, _receiver) = asyncband::spmc::bounded::(1); +//! use asyncband::spmc; +//! +//! let (sender, _receiver) = spmc::bounded::(1); //! let second_producer = sender.clone(); //! ``` //! //! ```compile_fail,E0599 -//! let (sender, _receiver) = asyncband::spmc::unbounded::(); +//! use asyncband::spmc; +//! +//! let (sender, _receiver) = spmc::unbounded::(); //! let second_producer = sender.clone(); //! ``` //! //! Sending through a shared reference is rejected: //! //! ```compile_fail,E0596 -//! fn send(sender: &asyncband::spmc::BoundedSender) { +//! use asyncband::spmc::BoundedSender; +//! +//! fn send(sender: &BoundedSender) { //! let _ = sender.try_send(1); //! } //! ``` //! //! ```compile_fail,E0596 -//! fn send(sender: &asyncband::spmc::UnboundedSender) { +//! use asyncband::spmc::UnboundedSender; +//! +//! fn send(sender: &UnboundedSender) { //! let _ = sender.send(1); //! } //! ``` @@ -78,7 +86,9 @@ //! A bounded `send` future retains the exclusive borrow until completion or cancellation: //! //! ```compile_fail,E0499 -//! let (mut sender, _receiver) = asyncband::spmc::bounded(1); +//! use asyncband::spmc; +//! +//! let (mut sender, _receiver) = spmc::bounded(1); //! let pending = sender.send(1); //! let _ = sender.try_send(2); //! drop(pending); @@ -89,13 +99,13 @@ mod error; mod queue; mod unbounded; -pub use self::bounded::BoundedReceiver; -pub use self::bounded::BoundedSender; -pub use self::bounded::bounded; -pub use self::error::RecvError; -pub use self::error::SendError; -pub use self::error::TryRecvError; -pub use self::error::TrySendError; -pub use self::unbounded::UnboundedReceiver; -pub use self::unbounded::UnboundedSender; -pub use self::unbounded::unbounded; +pub use crate::spmc::bounded::BoundedReceiver; +pub use crate::spmc::bounded::BoundedSender; +pub use crate::spmc::bounded::bounded; +pub use crate::spmc::error::RecvError; +pub use crate::spmc::error::SendError; +pub use crate::spmc::error::TryRecvError; +pub use crate::spmc::error::TrySendError; +pub use crate::spmc::unbounded::UnboundedReceiver; +pub use crate::spmc::unbounded::UnboundedSender; +pub use crate::spmc::unbounded::unbounded; diff --git a/asyncband/src/spmc/queue.rs b/asyncband/src/spmc/queue.rs index ad47bddf..9c8ce74d 100644 --- a/asyncband/src/spmc/queue.rs +++ b/asyncband/src/spmc/queue.rs @@ -22,13 +22,13 @@ use std::task::Context; use std::task::Poll; use std::task::Waker; -use super::RecvError; -use super::SendError; -use super::TryRecvError; -use super::TrySendError; use crate::internal::mutex::Mutex; use crate::internal::waitlist::WaitList; use crate::internal::waitlist::WaiterId; +use crate::spmc::RecvError; +use crate::spmc::SendError; +use crate::spmc::TryRecvError; +use crate::spmc::TrySendError; pub struct Shared { state: Mutex>, diff --git a/asyncband/src/spmc/unbounded.rs b/asyncband/src/spmc/unbounded.rs index b2b4851e..b5bb0b4b 100644 --- a/asyncband/src/spmc/unbounded.rs +++ b/asyncband/src/spmc/unbounded.rs @@ -18,11 +18,11 @@ use std::fmt; use std::sync::Arc; -use super::RecvError; -use super::SendError; -use super::TryRecvError; -use super::TrySendError; -use super::queue::Shared; +use crate::spmc::RecvError; +use crate::spmc::SendError; +use crate::spmc::TryRecvError; +use crate::spmc::TrySendError; +use crate::spmc::queue::Shared; /// Creates an unbounded single-producer, multi-consumer queue. /// diff --git a/asyncband/src/watch/error.rs b/asyncband/src/watch/error.rs index 017d6820..7f7121f7 100644 --- a/asyncband/src/watch/error.rs +++ b/asyncband/src/watch/error.rs @@ -16,6 +16,7 @@ // under the License. use std::any::type_name; +use std::error::Error; use std::fmt; /// An error returned when sending on a watch channel without any receivers. @@ -52,7 +53,7 @@ impl fmt::Debug for SendError { } } -impl std::error::Error for SendError {} +impl Error for SendError {} /// An error returned after all senders have been dropped and no unseen value remains. #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -67,4 +68,4 @@ impl fmt::Display for RecvError { } } -impl std::error::Error for RecvError {} +impl Error for RecvError {} diff --git a/asyncband/src/watch/mod.rs b/asyncband/src/watch/mod.rs index cc8d40e6..afc0928d 100644 --- a/asyncband/src/watch/mod.rs +++ b/asyncband/src/watch/mod.rs @@ -71,11 +71,11 @@ use std::sync::Arc; use std::task::Context; use std::task::Poll; -pub use self::error::RecvError; -pub use self::error::SendError; use crate::internal::mutex::Mutex; use crate::internal::wakerset::WakerSet; use crate::internal::wakerset::WakerToken; +pub use crate::watch::error::RecvError; +pub use crate::watch::error::SendError; /// Creates a watch channel with an initial value. /// diff --git a/asyncband/src/watch/tests.rs b/asyncband/src/watch/tests.rs index 6df8bb6f..27bfaf78 100644 --- a/asyncband/src/watch/tests.rs +++ b/asyncband/src/watch/tests.rs @@ -15,6 +15,8 @@ // specific language governing permissions and limitations // under the License. +use std::thread; + use super::*; #[test] @@ -42,7 +44,7 @@ fn concurrent_senders_commit_every_version() { let workers = (0..SENDERS) .map(|sender_index| { let tx = tx.clone(); - std::thread::spawn(move || { + thread::spawn(move || { for offset in 0..SENDS_PER_THREAD { tx.send(sender_index * SENDS_PER_THREAD + offset).unwrap(); } diff --git a/benchmarks/benches/ecosystem/broadcast/mpmc/adapters.rs b/benchmarks/benches/ecosystem/broadcast/mpmc/adapters.rs index 48e72e34..714fc715 100644 --- a/benchmarks/benches/ecosystem/broadcast/mpmc/adapters.rs +++ b/benchmarks/benches/ecosystem/broadcast/mpmc/adapters.rs @@ -19,7 +19,10 @@ use std::future::Future; use std::task::Context; use asyncband::blocking::FutureExt; +use asyncband::broadcast::mpmc as asyncband_mpmc; use benchmarks::support::poll_ready; +use tokio::sync::broadcast as tokio_broadcast; +use tokio::sync::broadcast::error::TryRecvError as TokioTryRecvError; pub struct Asyncband; pub struct Tokio; @@ -36,11 +39,11 @@ pub trait BroadcastMpmc: Send + Sync + 'static { } impl BroadcastMpmc for Asyncband { - type Receiver = asyncband::broadcast::mpmc::UnboundedReceiver; - type Sender = asyncband::broadcast::mpmc::UnboundedSender; + type Receiver = asyncband_mpmc::UnboundedReceiver; + type Sender = asyncband_mpmc::UnboundedSender; fn channel(_capacity: usize, receiver_count: usize) -> (Self::Sender, Vec) { - let (sender, receiver) = asyncband::broadcast::mpmc::unbounded(); + let (sender, receiver) = asyncband_mpmc::unbounded(); let mut receivers = Vec::with_capacity(receiver_count); receivers.push(receiver); for _ in 1..receiver_count { @@ -56,8 +59,8 @@ impl BroadcastMpmc for Asyncband { fn try_recv(receiver: &mut Self::Receiver) -> Option { match receiver.try_recv() { Ok(value) => Some(value), - Err(asyncband::broadcast::mpmc::TryRecvError::Empty) => None, - Err(asyncband::broadcast::mpmc::TryRecvError::Disconnected) => { + Err(asyncband_mpmc::TryRecvError::Empty) => None, + Err(asyncband_mpmc::TryRecvError::Disconnected) => { panic!("asyncband channel closed during benchmark") } } @@ -69,11 +72,11 @@ impl BroadcastMpmc for Asyncband { } impl BroadcastMpmc for Tokio { - type Receiver = tokio::sync::broadcast::Receiver; - type Sender = tokio::sync::broadcast::Sender; + type Receiver = tokio_broadcast::Receiver; + type Sender = tokio_broadcast::Sender; fn channel(capacity: usize, receiver_count: usize) -> (Self::Sender, Vec) { - let (sender, receiver) = tokio::sync::broadcast::channel(capacity); + let (sender, receiver) = tokio_broadcast::channel(capacity); let mut receivers = Vec::with_capacity(receiver_count); receivers.push(receiver); for _ in 1..receiver_count { @@ -89,7 +92,7 @@ impl BroadcastMpmc for Tokio { fn try_recv(receiver: &mut Self::Receiver) -> Option { match receiver.try_recv() { Ok(value) => Some(value), - Err(tokio::sync::broadcast::error::TryRecvError::Empty) => None, + Err(TokioTryRecvError::Empty) => None, Err(error) => panic!("unexpected Tokio receive error: {error}"), } } @@ -161,11 +164,11 @@ pub trait BoundedBroadcastMpmc: Send + Sync + 'static { } impl BoundedBroadcastMpmc for Asyncband { - type Receiver = asyncband::broadcast::mpmc::BoundedReceiver; - type Sender = asyncband::broadcast::mpmc::BoundedSender; + type Receiver = asyncband_mpmc::BoundedReceiver; + type Sender = asyncband_mpmc::BoundedSender; fn channel(capacity: usize, receiver_count: usize) -> (Self::Sender, Vec) { - let (sender, receiver) = asyncband::broadcast::mpmc::bounded(capacity); + let (sender, receiver) = asyncband_mpmc::bounded(capacity); let mut receivers = Vec::with_capacity(receiver_count); receivers.push(receiver); for _ in 1..receiver_count { @@ -189,8 +192,8 @@ impl BoundedBroadcastMpmc for Asyncband { fn try_recv(receiver: &mut Self::Receiver) -> Option { match receiver.try_recv() { Ok(value) => Some(value), - Err(asyncband::broadcast::mpmc::TryRecvError::Empty) => None, - Err(asyncband::broadcast::mpmc::TryRecvError::Disconnected) => { + Err(asyncband_mpmc::TryRecvError::Empty) => None, + Err(asyncband_mpmc::TryRecvError::Disconnected) => { panic!("asyncband channel closed during benchmark") } } diff --git a/benchmarks/benches/ecosystem/broadcast/mpmc/bounded.rs b/benchmarks/benches/ecosystem/broadcast/mpmc/bounded.rs index 88dba15c..262b4567 100644 --- a/benchmarks/benches/ecosystem/broadcast/mpmc/bounded.rs +++ b/benchmarks/benches/ecosystem/broadcast/mpmc/bounded.rs @@ -17,21 +17,23 @@ // Tokio broadcast overwrites at capacity, so it cannot participate in lossless backpressure cases. +use benchmarks::channels::runtime; use benchmarks::support::bench_context; use divan::Bencher; use divan::black_box; use divan::counter::ItemsCount; +use tokio::runtime::Builder; -use super::adapters::AsyncBroadcast; -use super::adapters::Asyncband; -use super::adapters::BoundedBroadcastMpmc; -use super::support::BACKPRESSURE_SHAPE; -use super::support::BATCH_MESSAGES; -use super::support::BOUNDED_SHAPES; -use super::support::BoundedConcurrent; -use super::support::BoundedShape; -use super::support::BoundedTasks; -use super::support::ROUND_TRIP_CAPACITY; +use crate::broadcast::mpmc::adapters::AsyncBroadcast; +use crate::broadcast::mpmc::adapters::Asyncband; +use crate::broadcast::mpmc::adapters::BoundedBroadcastMpmc; +use crate::broadcast::mpmc::support::BACKPRESSURE_SHAPE; +use crate::broadcast::mpmc::support::BATCH_MESSAGES; +use crate::broadcast::mpmc::support::BOUNDED_SHAPES; +use crate::broadcast::mpmc::support::BoundedConcurrent; +use crate::broadcast::mpmc::support::BoundedShape; +use crate::broadcast::mpmc::support::BoundedTasks; +use crate::broadcast::mpmc::support::ROUND_TRIP_CAPACITY; // Send-then-receive pairing keeps at most one message retained, so these never reach capacity. #[divan::bench(types = [Asyncband, AsyncBroadcast], sample_size = 512)] @@ -79,7 +81,7 @@ fn thread_batch(bencher: Bencher, shape: BoundedShape) counter = ItemsCount::new(BATCH_MESSAGES), )] fn task_batch(bencher: Bencher, shape: BoundedShape) { - let runtime = tokio::runtime::Builder::new_multi_thread() + let runtime = Builder::new_multi_thread() .worker_threads(4) .build() .unwrap(); @@ -91,7 +93,7 @@ fn task_batch(bencher: Bencher, shape: BoundedShape) { #[divan::bench(types = [Asyncband, AsyncBroadcast], sample_count = 10, sample_size = 1, counter = ItemsCount::new(BATCH_MESSAGES))] fn capacity_one_task_handoff(bencher: Bencher) { - let runtime = benchmarks::channels::runtime(4); + let runtime = runtime(4); bencher .with_inputs(|| BoundedTasks::new::(&runtime, BACKPRESSURE_SHAPE)) .bench_local_refs(|tasks| tasks.run(&runtime)); diff --git a/benchmarks/benches/ecosystem/broadcast/mpmc/no_backpressure.rs b/benchmarks/benches/ecosystem/broadcast/mpmc/no_backpressure.rs index c5a40722..1073fa4d 100644 --- a/benchmarks/benches/ecosystem/broadcast/mpmc/no_backpressure.rs +++ b/benchmarks/benches/ecosystem/broadcast/mpmc/no_backpressure.rs @@ -22,16 +22,16 @@ use divan::Bencher; use divan::black_box; use divan::counter::ItemsCount; -use super::adapters::AsyncBroadcast; -use super::adapters::Asyncband; -use super::adapters::BroadcastMpmc; -use super::adapters::Tokio; -use super::support::BATCH_MESSAGES; -use super::support::ConcurrentSend; -use super::support::Fanout; -use super::support::PRODUCER_COUNTS; -use super::support::RECEIVER_COUNTS; -use super::support::ROUND_TRIP_CAPACITY; +use crate::broadcast::mpmc::adapters::AsyncBroadcast; +use crate::broadcast::mpmc::adapters::Asyncband; +use crate::broadcast::mpmc::adapters::BroadcastMpmc; +use crate::broadcast::mpmc::adapters::Tokio; +use crate::broadcast::mpmc::support::BATCH_MESSAGES; +use crate::broadcast::mpmc::support::ConcurrentSend; +use crate::broadcast::mpmc::support::Fanout; +use crate::broadcast::mpmc::support::PRODUCER_COUNTS; +use crate::broadcast::mpmc::support::RECEIVER_COUNTS; +use crate::broadcast::mpmc::support::ROUND_TRIP_CAPACITY; #[divan::bench(types = [Asyncband, Tokio, AsyncBroadcast])] fn try_send_receive(bencher: Bencher) { diff --git a/benchmarks/benches/ecosystem/broadcast/mpmc/support.rs b/benchmarks/benches/ecosystem/broadcast/mpmc/support.rs index 1d07fd9e..19201883 100644 --- a/benchmarks/benches/ecosystem/broadcast/mpmc/support.rs +++ b/benchmarks/benches/ecosystem/broadcast/mpmc/support.rs @@ -24,10 +24,11 @@ use std::thread::JoinHandle; use divan::black_box; use tokio::runtime::Runtime; +use tokio::sync::Barrier as TokioBarrier; use tokio::task::JoinSet; -use super::adapters::BoundedBroadcastMpmc; -use super::adapters::BroadcastMpmc; +use crate::broadcast::mpmc::adapters::BoundedBroadcastMpmc; +use crate::broadcast::mpmc::adapters::BroadcastMpmc; pub const BATCH_MESSAGES: usize = 4096; pub const PRODUCER_COUNTS: &[usize] = &[1, 2, 4, 8]; @@ -252,7 +253,7 @@ impl BoundedConcurrent { } pub struct BoundedTasks { - start: Arc, + start: Arc, tasks: JoinSet<()>, } @@ -265,7 +266,7 @@ impl BoundedTasks { } = shape; assert_eq!(BATCH_MESSAGES % producers, 0); let (sender, receivers) = C::channel(capacity, receivers); - let start = Arc::new(tokio::sync::Barrier::new(producers + receivers.len() + 1)); + let start = Arc::new(TokioBarrier::new(producers + receivers.len() + 1)); let mut tasks = JoinSet::new(); for mut receiver in receivers { diff --git a/benchmarks/benches/ecosystem/mpsc/adapters.rs b/benchmarks/benches/ecosystem/mpsc/adapters.rs index cf28713b..df5cfb17 100644 --- a/benchmarks/benches/ecosystem/mpsc/adapters.rs +++ b/benchmarks/benches/ecosystem/mpsc/adapters.rs @@ -20,7 +20,9 @@ use std::future::Future; use std::task::Context; use asyncband::blocking::FutureExt; +use asyncband::mpsc as asyncband_mpsc; use benchmarks::support::poll_ready; +use tokio::sync::mpsc as tokio_mpsc; pub struct Asyncband; pub struct Tokio; @@ -55,11 +57,11 @@ pub trait UnboundedMpsc: Send + Sync + 'static { } impl BoundedMpsc for Asyncband { - type Receiver = asyncband::mpsc::BoundedReceiver; - type Sender = asyncband::mpsc::BoundedSender; + type Receiver = asyncband_mpsc::BoundedReceiver; + type Sender = asyncband_mpsc::BoundedSender; fn channel(capacity: usize) -> (Self::Sender, Self::Receiver) { - asyncband::mpsc::bounded(capacity) + asyncband_mpsc::bounded(capacity) } fn try_send(sender: &Self::Sender, value: T) { @@ -96,11 +98,11 @@ impl BoundedMpsc for Asyncband { } impl BoundedMpsc for Tokio { - type Receiver = tokio::sync::mpsc::Receiver; - type Sender = tokio::sync::mpsc::Sender; + type Receiver = tokio_mpsc::Receiver; + type Sender = tokio_mpsc::Sender; fn channel(capacity: usize) -> (Self::Sender, Self::Receiver) { - tokio::sync::mpsc::channel(capacity) + tokio_mpsc::channel(capacity) } fn try_send(sender: &Self::Sender, value: T) { @@ -219,11 +221,11 @@ impl BoundedMpsc for Flume { } impl UnboundedMpsc for Asyncband { - type Receiver = asyncband::mpsc::UnboundedReceiver; - type Sender = asyncband::mpsc::UnboundedSender; + type Receiver = asyncband_mpsc::UnboundedReceiver; + type Sender = asyncband_mpsc::UnboundedSender; fn channel() -> (Self::Sender, Self::Receiver) { - asyncband::mpsc::unbounded() + asyncband_mpsc::unbounded() } fn send(sender: &Self::Sender, value: T) { @@ -248,11 +250,11 @@ impl UnboundedMpsc for Asyncband { } impl UnboundedMpsc for Tokio { - type Receiver = tokio::sync::mpsc::UnboundedReceiver; - type Sender = tokio::sync::mpsc::UnboundedSender; + type Receiver = tokio_mpsc::UnboundedReceiver; + type Sender = tokio_mpsc::UnboundedSender; fn channel() -> (Self::Sender, Self::Receiver) { - tokio::sync::mpsc::unbounded_channel() + tokio_mpsc::unbounded_channel() } fn send(sender: &Self::Sender, value: T) { diff --git a/benchmarks/benches/ecosystem/mpsc/bounded.rs b/benchmarks/benches/ecosystem/mpsc/bounded.rs index 4c28cd1b..8d324f3f 100644 --- a/benchmarks/benches/ecosystem/mpsc/bounded.rs +++ b/benchmarks/benches/ecosystem/mpsc/bounded.rs @@ -20,20 +20,20 @@ use divan::Bencher; use divan::black_box; use divan::counter::ItemsCount; -use super::adapters::AsyncChannel; -use super::adapters::Asyncband; -use super::adapters::BoundedMpsc; -use super::adapters::Flume; -use super::adapters::Tokio; -use super::support::BATCH_MESSAGES; -use super::support::BOUNDED_CAPACITY; -use super::support::Bounded; -use super::support::PARALLEL_TASK_SHAPES; -use super::support::PRODUCER_COUNTS; -use super::support::RepeatedBatch; -use super::support::RepeatedTasks; -use super::support::TASK_SHAPES; -use super::support::TaskShape; +use crate::mpsc::adapters::AsyncChannel; +use crate::mpsc::adapters::Asyncband; +use crate::mpsc::adapters::BoundedMpsc; +use crate::mpsc::adapters::Flume; +use crate::mpsc::adapters::Tokio; +use crate::mpsc::support::BATCH_MESSAGES; +use crate::mpsc::support::BOUNDED_CAPACITY; +use crate::mpsc::support::Bounded; +use crate::mpsc::support::PARALLEL_TASK_SHAPES; +use crate::mpsc::support::PRODUCER_COUNTS; +use crate::mpsc::support::RepeatedBatch; +use crate::mpsc::support::RepeatedTasks; +use crate::mpsc::support::TASK_SHAPES; +use crate::mpsc::support::TaskShape; // Fixed sample sizes keep cold-start costs from skewing Divan's iteration count. #[divan::bench(types = [Asyncband, Tokio, AsyncChannel, Flume], sample_size = 512)] diff --git a/benchmarks/benches/ecosystem/mpsc/reservation.rs b/benchmarks/benches/ecosystem/mpsc/reservation.rs index 2f4502a9..8eda086e 100644 --- a/benchmarks/benches/ecosystem/mpsc/reservation.rs +++ b/benchmarks/benches/ecosystem/mpsc/reservation.rs @@ -19,20 +19,22 @@ use std::future::Future; use std::marker::PhantomData; use asyncband::blocking::FutureExt; +use asyncband::mpsc as asyncband_mpsc; use benchmarks::support::bench_context; use benchmarks::support::poll_ready; use divan::Bencher; use divan::black_box; use divan::counter::ItemsCount; +use tokio::sync::mpsc as tokio_mpsc; -use super::adapters::Asyncband; -use super::adapters::BoundedMpsc; -use super::adapters::Tokio; -use super::support::BATCH_MESSAGES; -use super::support::ConcurrentMpsc; -use super::support::RepeatedTasks; -use super::support::TASK_SHAPES; -use super::support::TaskShape; +use crate::mpsc::adapters::Asyncband; +use crate::mpsc::adapters::BoundedMpsc; +use crate::mpsc::adapters::Tokio; +use crate::mpsc::support::BATCH_MESSAGES; +use crate::mpsc::support::ConcurrentMpsc; +use crate::mpsc::support::RepeatedTasks; +use crate::mpsc::support::TASK_SHAPES; +use crate::mpsc::support::TaskShape; trait Reservable: BoundedMpsc { type Permit<'a>: Send; @@ -42,7 +44,7 @@ trait Reservable: BoundedMpsc { } impl Reservable for Asyncband { - type Permit<'a> = asyncband::mpsc::Permit<'a, usize>; + type Permit<'a> = asyncband_mpsc::Permit<'a, usize>; fn try_reserve(sender: &Self::Sender) -> Self::Permit<'_> { sender.try_reserve().unwrap() } @@ -55,7 +57,7 @@ impl Reservable for Asyncband { } impl Reservable for Tokio { - type Permit<'a> = tokio::sync::mpsc::Permit<'a, usize>; + type Permit<'a> = tokio_mpsc::Permit<'a, usize>; fn try_reserve(sender: &Self::Sender) -> Self::Permit<'_> { sender.try_reserve().unwrap() } diff --git a/benchmarks/benches/ecosystem/mpsc/support.rs b/benchmarks/benches/ecosystem/mpsc/support.rs index 37453f00..a098946b 100644 --- a/benchmarks/benches/ecosystem/mpsc/support.rs +++ b/benchmarks/benches/ecosystem/mpsc/support.rs @@ -28,9 +28,15 @@ use std::thread::JoinHandle; pub use benchmarks::channels::BATCH_MESSAGES; pub use benchmarks::channels::BOUNDED_CAPACITY; use divan::black_box; - -use super::adapters::BoundedMpsc; -use super::adapters::UnboundedMpsc; +use tokio::runtime::Builder; +use tokio::runtime::Runtime; +use tokio::sync::Barrier as TokioBarrier; +use tokio::sync::Notify; +use tokio::sync::mpsc; +use tokio::task::JoinHandle as TokioJoinHandle; + +use crate::mpsc::adapters::BoundedMpsc; +use crate::mpsc::adapters::UnboundedMpsc; pub const PRODUCER_COUNTS: &[usize] = &[1, 4]; #[derive(Clone, Copy)] @@ -248,19 +254,19 @@ impl> Drop for RepeatedBatch { // block_on instead measures worker-to-caller thread handoffs, which is a separate workload. enum Receiver { Task { - start: Arc, - completed: tokio::sync::mpsc::UnboundedReceiver, + start: Arc, + completed: mpsc::UnboundedReceiver, }, External(C::Receiver), } // Control messages coordinate each batch without forwarding measured payloads. pub struct RepeatedTasks { - runtime: tokio::runtime::Runtime, + runtime: Runtime, receiver: Receiver, - start: Arc, + start: Arc, stop: Arc, - workers: Vec>, + workers: Vec>, } impl RepeatedTasks { @@ -279,17 +285,15 @@ impl RepeatedTasks { ) -> Self { assert_eq!(BATCH_MESSAGES % producer_count, 0); let runtime = if worker_threads == 0 { - tokio::runtime::Builder::new_current_thread() - .build() - .unwrap() + Builder::new_current_thread().build().unwrap() } else { - tokio::runtime::Builder::new_multi_thread() + Builder::new_multi_thread() .worker_threads(worker_threads) .build() .unwrap() }; let (sender, mut receiver) = C::channel(); - let start = Arc::new(tokio::sync::Barrier::new(producer_count + 1)); + let start = Arc::new(TokioBarrier::new(producer_count + 1)); let stop = Arc::new(AtomicBool::new(false)); let messages_per_producer = BATCH_MESSAGES / producer_count; let mut workers: Vec<_> = (0..producer_count) @@ -316,8 +320,8 @@ impl RepeatedTasks { let receiver = if external_receiver { Receiver::External(receiver) } else { - let request = Arc::new(tokio::sync::Notify::new()); - let (completed_tx, completed) = tokio::sync::mpsc::unbounded_channel(); + let request = Arc::new(Notify::new()); + let (completed_tx, completed) = mpsc::unbounded_channel(); let request_rx = request.clone(); let start = start.clone(); let stop = stop.clone(); diff --git a/benchmarks/benches/ecosystem/mpsc/unbounded.rs b/benchmarks/benches/ecosystem/mpsc/unbounded.rs index 60f36117..a9fcd700 100644 --- a/benchmarks/benches/ecosystem/mpsc/unbounded.rs +++ b/benchmarks/benches/ecosystem/mpsc/unbounded.rs @@ -26,19 +26,22 @@ use benchmarks::support::bench_context; use divan::Bencher; use divan::black_box; use divan::counter::ItemsCount; +use tokio::runtime::Builder; +use tokio::sync::Notify; +use tokio::task::unconstrained; -use super::adapters::AsyncChannel; -use super::adapters::Asyncband; -use super::adapters::Flume; -use super::adapters::Tokio; -use super::adapters::UnboundedMpsc; -use super::support::BATCH_MESSAGES; -use super::support::PRODUCER_COUNTS; -use super::support::RepeatedBatch; -use super::support::RepeatedTasks; -use super::support::TASK_SHAPES; -use super::support::TaskShape; -use super::support::Unbounded; +use crate::mpsc::adapters::AsyncChannel; +use crate::mpsc::adapters::Asyncband; +use crate::mpsc::adapters::Flume; +use crate::mpsc::adapters::Tokio; +use crate::mpsc::adapters::UnboundedMpsc; +use crate::mpsc::support::BATCH_MESSAGES; +use crate::mpsc::support::PRODUCER_COUNTS; +use crate::mpsc::support::RepeatedBatch; +use crate::mpsc::support::RepeatedTasks; +use crate::mpsc::support::TASK_SHAPES; +use crate::mpsc::support::TaskShape; +use crate::mpsc::support::Unbounded; #[divan::bench(types = [Asyncband, Tokio, AsyncChannel, Flume])] fn ready_send_receive(bencher: Bencher) { @@ -185,14 +188,12 @@ fn scheduled_bursts_inline>( ) { assert_eq!(BATCH_MESSAGES % burst_messages, 0); assert_eq!(burst_messages % producers, 0); - let runtime = tokio::runtime::Builder::new_multi_thread() + let runtime = Builder::new_multi_thread() .worker_threads(4) .build() .unwrap(); let (sender, mut receiver) = C::channel(); - let start: Vec<_> = (0..producers) - .map(|_| Arc::new(tokio::sync::Notify::new())) - .collect(); + let start: Vec<_> = (0..producers).map(|_| Arc::new(Notify::new())).collect(); let stop = Arc::new(AtomicBool::new(false)); let workers: Vec<_> = start .iter() @@ -230,8 +231,7 @@ fn scheduled_bursts_inline>( // Exclude Tokio's cooperative-budget Pending from the initial empty probe. // Retain the same `recv_async` future so its channel registration drives the // wake. - let mut receive = - pin!(tokio::task::unconstrained(C::recv_async(&mut receiver))); + let mut receive = pin!(unconstrained(C::recv_async(&mut receiver))); let mut released = false; poll_fn(|cx| { let result = receive.as_mut().poll(cx); diff --git a/benchmarks/benches/ecosystem/waitgroup.rs b/benchmarks/benches/ecosystem/waitgroup.rs index f9886452..9ebd8f90 100644 --- a/benchmarks/benches/ecosystem/waitgroup.rs +++ b/benchmarks/benches/ecosystem/waitgroup.rs @@ -19,6 +19,7 @@ use std::future::Future; use std::future::IntoFuture; use std::pin::pin; +use asyncband::waitgroup as asyncband_waitgroup; use benchmarks::support::bench_context; use benchmarks::support::poll_pending; use benchmarks::support::poll_pinned_ready; @@ -41,9 +42,9 @@ trait WaitGroup { } impl WaitGroup for Asyncband { - type Group = asyncband::waitgroup::WaitGroup; - type Worker = asyncband::waitgroup::WaitGroup; - type Wait = asyncband::waitgroup::Wait; + type Group = asyncband_waitgroup::WaitGroup; + type Worker = asyncband_waitgroup::WaitGroup; + type Wait = asyncband_waitgroup::Wait; fn new() -> Self::Group { Self::Group::new() diff --git a/benchmarks/benches/ecosystem/watch/adapters.rs b/benchmarks/benches/ecosystem/watch/adapters.rs index f5a9b6e7..52cc1b03 100644 --- a/benchmarks/benches/ecosystem/watch/adapters.rs +++ b/benchmarks/benches/ecosystem/watch/adapters.rs @@ -17,6 +17,9 @@ use std::future::Future; +use asyncband::watch as asyncband_watch; +use tokio::sync::watch as tokio_watch; + pub struct Asyncband; pub struct Tokio; @@ -32,11 +35,11 @@ pub trait Watch: Send + Sync + 'static { } impl Watch for Asyncband { - type Sender = asyncband::watch::Sender; - type Receiver = asyncband::watch::Receiver; + type Sender = asyncband_watch::Sender; + type Receiver = asyncband_watch::Receiver; fn channel(receiver_count: usize) -> (Self::Sender, Vec) { - let (sender, first) = asyncband::watch::channel(0); + let (sender, first) = asyncband_watch::channel(0); let mut receivers = Vec::with_capacity(receiver_count); receivers.push(first); receivers.extend((1..receiver_count).map(|_| sender.subscribe())); @@ -61,11 +64,11 @@ impl Watch for Asyncband { } impl Watch for Tokio { - type Sender = tokio::sync::watch::Sender; - type Receiver = tokio::sync::watch::Receiver; + type Sender = tokio_watch::Sender; + type Receiver = tokio_watch::Receiver; fn channel(receiver_count: usize) -> (Self::Sender, Vec) { - let (sender, first) = tokio::sync::watch::channel(0); + let (sender, first) = tokio_watch::channel(0); let mut receivers = Vec::with_capacity(receiver_count); receivers.push(first); receivers.extend((1..receiver_count).map(|_| sender.subscribe())); diff --git a/benchmarks/benches/ecosystem/watch/paths.rs b/benchmarks/benches/ecosystem/watch/paths.rs index 0be7228e..aa66807a 100644 --- a/benchmarks/benches/ecosystem/watch/paths.rs +++ b/benchmarks/benches/ecosystem/watch/paths.rs @@ -27,9 +27,9 @@ use benchmarks::support::poll_ready; use divan::Bencher; use divan::black_box; -use super::adapters::Asyncband; -use super::adapters::Tokio; -use super::adapters::Watch; +use crate::watch::adapters::Asyncband; +use crate::watch::adapters::Tokio; +use crate::watch::adapters::Watch; const RECEIVER_COUNTS: &[usize] = &[2, 4, 8, 32]; diff --git a/benchmarks/benches/primitives/mpmc/bounded.rs b/benchmarks/benches/primitives/mpmc/bounded.rs index 13d36ef5..5c3e52ac 100644 --- a/benchmarks/benches/primitives/mpmc/bounded.rs +++ b/benchmarks/benches/primitives/mpmc/bounded.rs @@ -25,7 +25,7 @@ use benchmarks::support::poll_ready; use divan::Bencher; use divan::black_box; -use super::FAST_SAMPLE_SIZE; +use crate::mpmc::FAST_SAMPLE_SIZE; #[divan::bench(sample_size = FAST_SAMPLE_SIZE)] fn try_send_then_try_recv(bencher: Bencher) { diff --git a/benchmarks/benches/primitives/mpmc/unbounded.rs b/benchmarks/benches/primitives/mpmc/unbounded.rs index 59bec9b6..5e71cc56 100644 --- a/benchmarks/benches/primitives/mpmc/unbounded.rs +++ b/benchmarks/benches/primitives/mpmc/unbounded.rs @@ -25,7 +25,7 @@ use benchmarks::support::poll_ready; use divan::Bencher; use divan::black_box; -use super::FAST_SAMPLE_SIZE; +use crate::mpmc::FAST_SAMPLE_SIZE; #[divan::bench(sample_size = FAST_SAMPLE_SIZE)] fn send_then_try_recv(bencher: Bencher) { diff --git a/benchmarks/benches/primitives/once_map/initialize.rs b/benchmarks/benches/primitives/once_map/initialize.rs index 3218a361..fe378fbb 100644 --- a/benchmarks/benches/primitives/once_map/initialize.rs +++ b/benchmarks/benches/primitives/once_map/initialize.rs @@ -27,12 +27,12 @@ use divan::Bencher; use divan::black_box; use divan::counter::ItemsCount; -use super::support::BATCH_SAMPLE_SIZE; -use super::support::BATCH_SIZES; -use super::support::BenchMap; -use super::support::FAST_SAMPLE_SIZE; -use super::support::READY_ENTRY_COUNTS; -use super::support::ready_map; +use crate::once_map::support::BATCH_SAMPLE_SIZE; +use crate::once_map::support::BATCH_SIZES; +use crate::once_map::support::BenchMap; +use crate::once_map::support::FAST_SAMPLE_SIZE; +use crate::once_map::support::READY_ENTRY_COUNTS; +use crate::once_map::support::ready_map; const ABSENT_KEY: usize = usize::MAX; diff --git a/benchmarks/benches/primitives/once_map/lookup.rs b/benchmarks/benches/primitives/once_map/lookup.rs index 3b708753..bfef1cca 100644 --- a/benchmarks/benches/primitives/once_map/lookup.rs +++ b/benchmarks/benches/primitives/once_map/lookup.rs @@ -20,13 +20,13 @@ use benchmarks::support::poll_ready; use divan::Bencher; use divan::black_box; -use super::support::CONTENDED_SAMPLE_SIZE; -use super::support::HOT_ENTRY_COUNTS; -use super::support::READY_ENTRY_COUNTS; -use super::support::THREAD_COUNTS; -use super::support::distributed_absent_key; -use super::support::distributed_ready_key; -use super::support::ready_map; +use crate::once_map::support::CONTENDED_SAMPLE_SIZE; +use crate::once_map::support::HOT_ENTRY_COUNTS; +use crate::once_map::support::READY_ENTRY_COUNTS; +use crate::once_map::support::THREAD_COUNTS; +use crate::once_map::support::distributed_absent_key; +use crate::once_map::support::distributed_ready_key; +use crate::once_map::support::ready_map; #[divan::bench(threads = THREAD_COUNTS, sample_size = CONTENDED_SAMPLE_SIZE)] fn get_hit_same_key(bencher: Bencher) { diff --git a/benchmarks/benches/primitives/once_map/maintenance.rs b/benchmarks/benches/primitives/once_map/maintenance.rs index e939ca13..39c8e8e1 100644 --- a/benchmarks/benches/primitives/once_map/maintenance.rs +++ b/benchmarks/benches/primitives/once_map/maintenance.rs @@ -19,11 +19,11 @@ use benchmarks::support::defer_input_drop; use divan::Bencher; use divan::black_box; -use super::support::BATCH_SAMPLE_SIZE; -use super::support::FAST_SAMPLE_SIZE; -use super::support::NONEMPTY_ENTRY_COUNTS; -use super::support::READY_ENTRY_COUNTS; -use super::support::ready_map; +use crate::once_map::support::BATCH_SAMPLE_SIZE; +use crate::once_map::support::FAST_SAMPLE_SIZE; +use crate::once_map::support::NONEMPTY_ENTRY_COUNTS; +use crate::once_map::support::READY_ENTRY_COUNTS; +use crate::once_map::support::ready_map; #[divan::bench(args = NONEMPTY_ENTRY_COUNTS, sample_size = BATCH_SAMPLE_SIZE)] fn remove_hit(bencher: Bencher, ready_entries: usize) { diff --git a/benchmarks/benches/primitives/singleflight/coalescing.rs b/benchmarks/benches/primitives/singleflight/coalescing.rs index a52ec48b..dd244910 100644 --- a/benchmarks/benches/primitives/singleflight/coalescing.rs +++ b/benchmarks/benches/primitives/singleflight/coalescing.rs @@ -25,9 +25,9 @@ use divan::Bencher; use divan::black_box; use divan::counter::ItemsCount; -use super::support::BATCH_SAMPLE_SIZE; -use super::support::BATCH_SIZES; -use super::support::BenchGroup; +use crate::singleflight::support::BATCH_SAMPLE_SIZE; +use crate::singleflight::support::BATCH_SIZES; +use crate::singleflight::support::BenchGroup; // Measures the complete successful fan-in: one leader is suspended, every duplicate joins it, and // all callers receive the cloned result after the leader completes. diff --git a/benchmarks/benches/primitives/singleflight/leaders.rs b/benchmarks/benches/primitives/singleflight/leaders.rs index 28355dcd..ca1675ad 100644 --- a/benchmarks/benches/primitives/singleflight/leaders.rs +++ b/benchmarks/benches/primitives/singleflight/leaders.rs @@ -26,13 +26,13 @@ use divan::Bencher; use divan::black_box; use divan::counter::ItemsCount; -use super::support::BATCH_SAMPLE_SIZE; -use super::support::BATCH_SIZES; -use super::support::BenchGroup; -use super::support::CONTENDED_SAMPLE_SIZE; -use super::support::FAST_SAMPLE_SIZE; -use super::support::THREAD_COUNTS; -use super::support::unique_thread_key; +use crate::singleflight::support::BATCH_SAMPLE_SIZE; +use crate::singleflight::support::BATCH_SIZES; +use crate::singleflight::support::BenchGroup; +use crate::singleflight::support::CONTENDED_SAMPLE_SIZE; +use crate::singleflight::support::FAST_SAMPLE_SIZE; +use crate::singleflight::support::THREAD_COUNTS; +use crate::singleflight::support::unique_thread_key; // Reuse the group so table capacity survives completed calls. #[divan::bench(sample_size = FAST_SAMPLE_SIZE)] diff --git a/benchmarks/src/channels/adapters.rs b/benchmarks/src/channels/adapters.rs index 9ef3fd0c..488fc021 100644 --- a/benchmarks/src/channels/adapters.rs +++ b/benchmarks/src/channels/adapters.rs @@ -19,8 +19,10 @@ use std::future::Future; use std::marker::PhantomData; use asyncband::blocking::FutureExt; +use asyncband::mpmc; +use asyncband::spmc; -use super::BOUNDED_CAPACITY; +use crate::channels::BOUNDED_CAPACITY; pub struct Mpmc; pub struct Spmc; @@ -41,11 +43,11 @@ pub trait Channel: Send + Sync + 'static { } impl Channel for Bounded { - type Sender = asyncband::spmc::BoundedSender; - type Receiver = asyncband::spmc::BoundedReceiver; + type Sender = spmc::BoundedSender; + type Receiver = spmc::BoundedReceiver; fn channel() -> (Self::Sender, Self::Receiver) { - asyncband::spmc::bounded(CAPACITY) + spmc::bounded(CAPACITY) } async fn send(sender: &mut Self::Sender, value: usize) { @@ -58,11 +60,11 @@ impl Channel for Bounded { } impl Channel for Unbounded { - type Sender = asyncband::spmc::UnboundedSender; - type Receiver = asyncband::spmc::UnboundedReceiver; + type Sender = spmc::UnboundedSender; + type Receiver = spmc::UnboundedReceiver; fn channel() -> (Self::Sender, Self::Receiver) { - asyncband::spmc::unbounded() + spmc::unbounded() } async fn send(sender: &mut Self::Sender, value: usize) { @@ -139,11 +141,11 @@ pub trait UnboundedMpmc: Send + Sync + 'static { } impl BoundedMpmc for Mpmc { - type Receiver = asyncband::mpmc::BoundedReceiver; - type Sender = asyncband::mpmc::BoundedSender; + type Receiver = mpmc::BoundedReceiver; + type Sender = mpmc::BoundedSender; fn channel(capacity: usize) -> (Self::Sender, Self::Receiver) { - asyncband::mpmc::bounded(capacity) + mpmc::bounded(capacity) } async fn send_async(sender: &Self::Sender, value: usize) { @@ -159,11 +161,11 @@ impl BoundedMpmc for Mpmc { } impl UnboundedMpmc for Mpmc { - type Receiver = asyncband::mpmc::UnboundedReceiver; - type Sender = asyncband::mpmc::UnboundedSender; + type Receiver = mpmc::UnboundedReceiver; + type Sender = mpmc::UnboundedSender; fn channel() -> (Self::Sender, Self::Receiver) { - asyncband::mpmc::unbounded() + mpmc::unbounded() } fn send(sender: &Self::Sender, value: usize) { diff --git a/benchmarks/src/channels/mod.rs b/benchmarks/src/channels/mod.rs index b70e390e..3eb3adf6 100644 --- a/benchmarks/src/channels/mod.rs +++ b/benchmarks/src/channels/mod.rs @@ -15,6 +15,7 @@ // specific language governing permissions and limitations // under the License. +use tokio::runtime::Builder; use tokio::runtime::Runtime; pub mod adapters; @@ -26,11 +27,9 @@ pub const BOUNDED_CAPACITY: usize = 64; pub fn runtime(worker_threads: usize) -> Runtime { if worker_threads == 0 { - tokio::runtime::Builder::new_current_thread() - .build() - .unwrap() + Builder::new_current_thread().build().unwrap() } else { - tokio::runtime::Builder::new_multi_thread() + Builder::new_multi_thread() .worker_threads(worker_threads) .build() .unwrap() diff --git a/benchmarks/src/channels/mpmc.rs b/benchmarks/src/channels/mpmc.rs index d7582f36..a32606b4 100644 --- a/benchmarks/src/channels/mpmc.rs +++ b/benchmarks/src/channels/mpmc.rs @@ -23,12 +23,13 @@ use std::thread::JoinHandle; use divan::black_box; use tokio::runtime::Runtime; +use tokio::sync::Barrier as TokioBarrier; use tokio::task::JoinSet; -use super::BATCH_MESSAGES; -use super::adapters::BoundedMpmc; -use super::adapters::Channel; -use super::adapters::UnboundedMpmc; +use crate::channels::BATCH_MESSAGES; +use crate::channels::adapters::BoundedMpmc; +use crate::channels::adapters::Channel; +use crate::channels::adapters::UnboundedMpmc; #[derive(Clone, Copy, Debug)] pub struct Topology { @@ -76,7 +77,7 @@ pub const TOPOLOGIES: &[Topology] = &[ // The caller only coordinates the batch. Spawned tasks send and receive all measured messages, // including on the current-thread runtime; `Runtime::block_on` itself receives no data. pub struct TaskBatch { - start: Arc, + start: Arc, workers: JoinSet<(usize, usize)>, } @@ -87,7 +88,7 @@ impl TaskBatch { { assert_eq!(BATCH_MESSAGES % topology.producers, 0); let (sender, receiver) = C::channel(); - let start = Arc::new(tokio::sync::Barrier::new( + let start = Arc::new(TokioBarrier::new( topology.producers + topology.consumers + 1, )); let messages_per_producer = BATCH_MESSAGES / topology.producers; diff --git a/benchmarks/src/channels/spmc.rs b/benchmarks/src/channels/spmc.rs index 2e99c5c1..efdc7d29 100644 --- a/benchmarks/src/channels/spmc.rs +++ b/benchmarks/src/channels/spmc.rs @@ -19,22 +19,23 @@ use std::sync::Arc; use divan::black_box; use tokio::runtime::Runtime; +use tokio::sync::Barrier; use tokio::task::JoinSet; -use super::BATCH_MESSAGES; -use super::adapters::Channel; +use crate::channels::BATCH_MESSAGES; +use crate::channels::adapters::Channel; pub const CONSUMERS: &[usize] = &[1, 2, 4, 8]; pub struct TaskBatch { - start: Arc, + start: Arc, tasks: JoinSet<(usize, usize)>, } impl TaskBatch { pub fn new(runtime: &Runtime, consumers: usize) -> Self { let (mut sender, receiver) = C::channel(); - let start = Arc::new(tokio::sync::Barrier::new(consumers + 2)); + let start = Arc::new(Barrier::new(consumers + 2)); let mut tasks = JoinSet::new(); let producer_start = start.clone(); tasks.spawn_on( diff --git a/examples/src/coalesced_worker.rs b/examples/src/coalesced_worker.rs index 52a1cd3c..21fdff44 100644 --- a/examples/src/coalesced_worker.rs +++ b/examples/src/coalesced_worker.rs @@ -23,6 +23,7 @@ use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; use asyncband::event::AutoResetEvent; +use tokio::task::yield_now; #[derive(Default)] struct Rebuilder { @@ -70,7 +71,7 @@ async fn main() { rebuilder.request(1); rebuilder.request(2); rebuilder.request(3); - tokio::task::yield_now().await; + yield_now().await; // After rebuilding revision 3, the worker waits for another update. rebuilder.request(4); diff --git a/examples/src/graceful_shutdown.rs b/examples/src/graceful_shutdown.rs index 36ec43ea..ee800e66 100644 --- a/examples/src/graceful_shutdown.rs +++ b/examples/src/graceful_shutdown.rs @@ -23,7 +23,9 @@ use std::time::Duration; use asyncband::shutdown; use asyncband::shutdown::ShutdownGuard; +use tokio::signal::ctrl_c; use tokio::sync::oneshot; +use tokio::time::sleep; #[tokio::main(flavor = "current_thread")] async fn main() -> Result<(), Box> { @@ -33,7 +35,7 @@ async fn main() -> Result<(), Box> { // A real service can give this sender to an administrative endpoint. let (_admin_shutdown_tx, admin_shutdown_rx) = oneshot::channel::<()>(); let reason = tokio::select! { - result = tokio::signal::ctrl_c() => { + result = ctrl_c() => { result?; "Ctrl+C" } @@ -49,7 +51,7 @@ async fn main() -> Result<(), Box> { shutdown.request_shutdown(); let completed = tokio::select! { _ = shutdown => true, - _ = tokio::time::sleep(Duration::from_secs(30)) => false, + _ = sleep(Duration::from_secs(30)) => false, }; if !completed { @@ -70,7 +72,7 @@ async fn run_worker(guard: ShutdownGuard) { loop { tokio::select! { _ = guard.shutdown_requested() => break, - _ = tokio::time::sleep(Duration::from_secs(1)) => { + _ = sleep(Duration::from_secs(1)) => { println!("worker completed another unit of work"); } } diff --git a/examples/src/lazy_cell_boxed_vs_inline.rs b/examples/src/lazy_cell_boxed_vs_inline.rs index 5bc1d8ca..fb3e2ade 100644 --- a/examples/src/lazy_cell_boxed_vs_inline.rs +++ b/examples/src/lazy_cell_boxed_vs_inline.rs @@ -18,9 +18,11 @@ //! Choose how to store a lazy initializer: box its future to keep the cell movable, pin the cell //! locally to store the future inline, or share a pinned cell across tasks. +use std::pin::pin; use std::sync::Arc; use asyncband::once::LazyCell; +use tokio::task::yield_now; #[tokio::main(flavor = "current_thread")] async fn main() { @@ -32,7 +34,7 @@ async fn main() { // Returning the async future directly stores it inline. The caller pins the cell before the // first poll, so the future stays at a stable address without a heap allocation. let inline = LazyCell::new(async || "inline".to_owned()); - let mut inline = std::pin::pin!(inline); + let mut inline = pin!(inline); assert_eq!(LazyCell::force_pin(inline.as_ref()).await, "inline"); LazyCell::force_pin_mut(inline.as_mut()) @@ -46,7 +48,7 @@ async fn main() { // Arc::pin allocates the cell once and keeps its inline future at a stable address. Cloning the // pinned Arc lets multiple tasks resume the same future without a separate future allocation. let shared = Arc::pin(LazyCell::new(async || { - tokio::task::yield_now().await; + yield_now().await; "shared".to_owned() })); diff --git a/examples/src/notify_vs_event.rs b/examples/src/notify_vs_event.rs index 5c6e7598..1b1fa1df 100644 --- a/examples/src/notify_vs_event.rs +++ b/examples/src/notify_vs_event.rs @@ -30,6 +30,7 @@ use std::sync::atomic::Ordering; use asyncband::event::AutoResetEvent; use asyncband::watch; use tokio::sync::Notify; +use tokio::task::yield_now; #[tokio::main(flavor = "current_thread")] async fn main() { @@ -112,7 +113,7 @@ async fn index_readers_with_notify() { // The indexer finishes applying this revision before publishing it. indexed.store(revision, Ordering::Release); changed.notify_waiters(); - tokio::task::yield_now().await; + yield_now().await; } }; @@ -158,7 +159,7 @@ async fn index_readers_with_watch() { for revision in 1..=2 { // Publishing also works when there are temporarily no requests listening. indexed.send_replace(revision); - tokio::task::yield_now().await; + yield_now().await; } }; diff --git a/examples/src/once_cell_vs_lazy_cell.rs b/examples/src/once_cell_vs_lazy_cell.rs index caad33a2..c4f339d1 100644 --- a/examples/src/once_cell_vs_lazy_cell.rs +++ b/examples/src/once_cell_vs_lazy_cell.rs @@ -20,6 +20,7 @@ //! cancellation. use std::future::Ready; +use std::future::ready; use std::sync::Arc; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; @@ -32,7 +33,7 @@ static ONCE_ENDPOINT: OnceCell = OnceCell::new(); static LAZY_ENDPOINT: LazyCell> = LazyCell::new(load_default_endpoint); fn load_default_endpoint() -> Ready { - std::future::ready("https://service.example".to_owned()) + ready("https://service.example".to_owned()) } #[tokio::main(flavor = "current_thread")] diff --git a/examples/src/phaser_completion.rs b/examples/src/phaser_completion.rs index a1da43f9..fca613f6 100644 --- a/examples/src/phaser_completion.rs +++ b/examples/src/phaser_completion.rs @@ -36,6 +36,7 @@ use std::sync::atomic::Ordering; use asyncband::phaser::Closed; use asyncband::phaser::Phaser; use asyncband::phaser::PhaserParticipant; +use tokio::task::yield_now; // Own this guard before constructing a task future so cancelling an unpolled task also aborts. struct CloseOnDrop([Phaser; 2]); @@ -113,7 +114,7 @@ async fn publish_until_target() -> Result<(), Closed> { .map(|value| value.load(Ordering::Relaxed)) .sum(); // An async checkpoint can be awaited here while workers wait at resume. - tokio::task::yield_now().await; + yield_now().await; published.store(sum, Ordering::Relaxed); println!("coordinator: published aggregate {sum}"); if sum >= 18 { diff --git a/examples/src/phaser_rounds.rs b/examples/src/phaser_rounds.rs index b8a35424..a2a0f162 100644 --- a/examples/src/phaser_rounds.rs +++ b/examples/src/phaser_rounds.rs @@ -25,9 +25,12 @@ //! These are coordination patterns for jobs such as parallel imports. The work within a batch is //! represented by a yield; the examples focus on when workers can join, proceed, and leave. +use std::future::ready; + use asyncband::phaser::Closed; use asyncband::phaser::Phaser; use asyncband::phaser::PhaserParticipant; +use tokio::task::yield_now; #[tokio::main(flavor = "current_thread")] async fn main() -> Result<(), Closed> { @@ -62,7 +65,7 @@ async fn work(mut participant: PhaserParticipant, rounds: usize) -> Result<(), C for _ in 0..rounds { let observed = participant.arrive()?; // This work does not hold up the other participants' arrivals. - tokio::task::yield_now().await; + yield_now().await; let next = participant.wait().await?; assert_ne!(observed, next); } @@ -125,7 +128,7 @@ async fn cancellation_retry() -> Result<(), Closed> { biased; result = participant.wait() => panic!("peer has not arrived: {result:?}"), // Poll the wait once, then cancel it deterministically without a timer or sleep. - _ = std::future::ready(()) => {} + _ = ready(()) => {} } assert_eq!(phaser.arrived_parties(), 1); peer.arrive()?; diff --git a/examples/src/shared_completion.rs b/examples/src/shared_completion.rs index 4087927b..0e1a32a5 100644 --- a/examples/src/shared_completion.rs +++ b/examples/src/shared_completion.rs @@ -21,7 +21,10 @@ //! require one channel per consumer and manual fan-out, and a late consumer would need separate //! result storage. Completion retains the result and exposes it to every observer. +use std::ptr; + use asyncband::completion; +use tokio::task::yield_now; #[tokio::main(flavor = "current_thread")] async fn main() { @@ -30,7 +33,7 @@ async fn main() { let audit_log = completion.clone(); let worker = tokio::spawn(async move { - tokio::task::yield_now().await; + yield_now().await; completer .complete(String::from("build 42 succeeded")) .unwrap(); @@ -44,7 +47,7 @@ async fn main() { let late_observer = completion.clone(); let late_result = late_observer.wait().await.unwrap(); - assert!(std::ptr::eq(dashboard_result, audit_result)); - assert!(std::ptr::eq(dashboard_result, late_result)); + assert!(ptr::eq(dashboard_result, audit_result)); + assert!(ptr::eq(dashboard_result, late_result)); println!("{late_result}"); } diff --git a/tests-integration/src/lib.rs b/tests-integration/src/lib.rs index 58e9fc89..a60bec49 100644 --- a/tests-integration/src/lib.rs +++ b/tests-integration/src/lib.rs @@ -16,16 +16,22 @@ // under the License. use std::future::Future; +use std::panic::AssertUnwindSafe; +use std::panic::catch_unwind; +use std::panic::resume_unwind; use std::pin::Pin; use std::sync::Arc; use std::sync::Mutex; use std::sync::OnceLock; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; +use std::sync::mpsc; use std::task::Context; use std::task::Poll; use std::task::Wake; use std::task::Waker; +use std::thread; +use std::time::Duration; use tokio::runtime::Runtime; @@ -115,20 +121,20 @@ pub fn waker_on_drop(callback: impl FnOnce() + Send + 'static) -> Waker { } pub fn assert_completes_without_deadlock(test: impl FnOnce() + Send + 'static) { - let (finished_tx, finished_rx) = std::sync::mpsc::channel(); - let worker = std::thread::spawn(move || { - let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(test)); + let (finished_tx, finished_rx) = mpsc::channel(); + let worker = thread::spawn(move || { + let result = catch_unwind(AssertUnwindSafe(test)); finished_tx.send(result).unwrap(); }); #[cfg(not(miri))] let result = finished_rx - .recv_timeout(std::time::Duration::from_secs(10)) + .recv_timeout(Duration::from_secs(10)) .expect("test did not finish"); // Miri detects deadlock itself; its interpretation time must not determine test success. #[cfg(miri)] let result = finished_rx.recv().expect("test did not finish"); worker.join().unwrap(); if let Err(payload) = result { - std::panic::resume_unwind(payload); + resume_unwind(payload); } } diff --git a/tests-integration/tests/blocking_test.rs b/tests-integration/tests/blocking_test.rs index 5f5e7511..9afcf7a4 100644 --- a/tests-integration/tests/blocking_test.rs +++ b/tests-integration/tests/blocking_test.rs @@ -16,6 +16,8 @@ // under the License. use std::future::Future; +use std::future::pending; +use std::future::poll_fn; use std::pin::Pin; use std::sync::Arc; use std::sync::Mutex; @@ -26,7 +28,7 @@ use std::task::Waker; use std::thread; use std::time::Duration; -use asyncband::blocking::FutureExt as _; +use asyncband::blocking::FutureExt; // Long timeouts in this test target are watchdogs for detecting a stalled test process, not // assertions about elapsed-time precision. @@ -35,24 +37,18 @@ const TEST_WATCHDOG: Duration = Duration::from_secs(5); #[test] fn block_on_supports_method_and_ufcs_syntax() { assert_eq!(async { 42 }.block_on(), 42); - assert_eq!(asyncband::blocking::FutureExt::block_on(async { 7 }), 7); + assert_eq!(FutureExt::block_on(async { 7 }), 7); } #[test] fn wait_timeout_polls_before_checking_the_deadline() { assert_eq!(async { 42 }.wait_timeout(Duration::ZERO), Some(42)); - assert_eq!( - std::future::pending::<()>().wait_timeout(Duration::ZERO), - None - ); + assert_eq!(pending::<()>().wait_timeout(Duration::ZERO), None); } #[test] fn pending_future_times_out() { - assert_eq!( - std::future::pending::<()>().wait_timeout(Duration::from_millis(1)), - None - ); + assert_eq!(pending::<()>().wait_timeout(Duration::from_millis(1)), None); } #[test] @@ -72,7 +68,7 @@ fn nested_waits_use_independent_notifications() { let (done_tx, done_rx) = mpsc::channel(); let worker = thread::spawn(move || { let mut outer_polled = false; - let output = std::future::poll_fn(|outer_context| { + let output = poll_fn(|outer_context| { if outer_polled { Poll::Ready(42) } else { @@ -80,7 +76,7 @@ fn nested_waits_use_independent_notifications() { outer_context.waker().wake_by_ref(); let mut inner_polled = false; - let inner_output = std::future::poll_fn(|inner_context| { + let inner_output = poll_fn(|inner_context| { if inner_polled { Poll::Ready(7) } else { diff --git a/tests-integration/tests/broadcast_test/bounded.rs b/tests-integration/tests/broadcast_test/bounded.rs index 5423783e..23e6a8af 100644 --- a/tests-integration/tests/broadcast_test/bounded.rs +++ b/tests-integration/tests/broadcast_test/bounded.rs @@ -16,9 +16,12 @@ // under the License. use std::future::Future; +use std::panic::AssertUnwindSafe; +use std::panic::catch_unwind; use std::sync::Arc; use std::sync::Barrier; use std::task::Context; +use std::task::Poll; use std::task::Waker; use std::thread; @@ -291,7 +294,7 @@ fn parked_recv_that_reclaims_wakes_a_blocked_sender() { // Reclaim through the `recv` future rather than `try_recv`: it is a separate call site, and a // release wired into only one of them would strand this producer. let mut recv = Box::pin(rx.recv()); - assert_eq!(poll_once(recv.as_mut()), std::task::Poll::Ready(Ok(0))); + assert_eq!(poll_once(recv.as_mut()), Poll::Ready(Ok(0))); drop(recv); assert_eq!(tracker.count(), 1); @@ -535,7 +538,7 @@ fn bounded_parked_recv_wakes_when_the_last_sender_drops() { assert_eq!(tracker.count(), 1); assert_eq!( poll_once(recv.as_mut()), - std::task::Poll::Ready(Err(RecvError::Disconnected)) + Poll::Ready(Err(RecvError::Disconnected)) ); } @@ -602,9 +605,7 @@ fn bounded_panicking_clone_leaves_the_channel_consistent() { .unwrap(); // Two receivers share the payload, so `try_recv` has to clone it. - let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { - rx1.try_recv().map(|msg| msg.value) - })); + let result = catch_unwind(AssertUnwindSafe(|| rx1.try_recv().map(|msg| msg.value))); assert!(result.is_err()); // The panicking `try_recv` call still consumed the message for `rx1`, and left the channel @@ -636,7 +637,7 @@ fn panicking_payload_destructor_still_releases_capacity() { // Dropping `rx2` reclaims all three retained messages and their destructors panic. The // capacity they released must already have reached the parked producer by then. - let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| drop(rx2))); + let result = catch_unwind(AssertUnwindSafe(|| drop(rx2))); assert!(result.is_err()); assert!( diff --git a/tests-integration/tests/broadcast_test/unbounded.rs b/tests-integration/tests/broadcast_test/unbounded.rs index 3324e4d9..fd70417a 100644 --- a/tests-integration/tests/broadcast_test/unbounded.rs +++ b/tests-integration/tests/broadcast_test/unbounded.rs @@ -15,6 +15,8 @@ // specific language governing permissions and limitations // under the License. +use std::panic::AssertUnwindSafe; +use std::panic::catch_unwind; use std::sync::Arc; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; @@ -264,9 +266,7 @@ fn panicking_clone_leaves_the_channel_consistent() { }); // Two receivers share the payload, so `try_recv` has to clone it. - let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { - rx1.try_recv().map(|msg| msg.value) - })); + let result = catch_unwind(AssertUnwindSafe(|| rx1.try_recv().map(|msg| msg.value))); assert!(result.is_err()); // The panicking `try_recv` call still consumed the message for `rx1`, and left the channel diff --git a/tests-integration/tests/completion_test.rs b/tests-integration/tests/completion_test.rs index 4ea0afc1..8e411ef8 100644 --- a/tests-integration/tests/completion_test.rs +++ b/tests-integration/tests/completion_test.rs @@ -16,6 +16,7 @@ // under the License. use std::cell::Cell; +use std::ptr; use std::sync::Arc; use std::sync::Barrier; use std::task::Poll; @@ -45,13 +46,13 @@ fn all_observers_borrow_the_same_non_clone_value() { let second_value = FutureExt::block_on(second.wait()).unwrap(); let repeated = FutureExt::block_on(first.wait()).unwrap(); assert_eq!(first_value.0.as_str(), "ready"); - assert!(std::ptr::eq(first_value, second_value)); - assert!(std::ptr::eq(first_value, repeated)); + assert!(ptr::eq(first_value, second_value)); + assert!(ptr::eq(first_value, repeated)); let late = first.clone(); drop(first); let late_value = FutureExt::block_on(late.wait()).unwrap(); - assert!(std::ptr::eq(second_value, late_value)); + assert!(ptr::eq(second_value, late_value)); } #[test] diff --git a/tests-integration/tests/condvar_test.rs b/tests-integration/tests/condvar_test.rs index 4c2174e4..69572d27 100644 --- a/tests-integration/tests/condvar_test.rs +++ b/tests-integration/tests/condvar_test.rs @@ -27,6 +27,7 @@ use tests_integration::poll_once; use tests_integration::poll_with; use tests_integration::test_runtime; use tokio::task::JoinHandle; +use tokio::task::yield_now; struct NotifyOnDrop(Arc); @@ -144,7 +145,7 @@ fn notify_all_wakes_current_waiters_using_a_predicate_loop() { break; } drop(state); - tokio::task::yield_now().await; + yield_now().await; } // Seeing every task's `waiting` update while holding this mutex also means every task has diff --git a/tests-integration/tests/latch_test.rs b/tests-integration/tests/latch_test.rs index 7a4e6c6c..ba37f83c 100644 --- a/tests-integration/tests/latch_test.rs +++ b/tests-integration/tests/latch_test.rs @@ -21,6 +21,7 @@ use std::task::Waker; use asyncband::latch::Latch; use tests_integration::WakeCounter; +use tokio::sync::Barrier; #[test] fn countdown_operations_saturate_at_zero() { @@ -97,7 +98,7 @@ async fn concurrent_arrivals_complete_the_latch() { const TASKS: usize = 32; let latch = Arc::new(Latch::new(TASKS as u32)); - let start = Arc::new(tokio::sync::Barrier::new(TASKS + 1)); + let start = Arc::new(Barrier::new(TASKS + 1)); let mut tasks = Vec::with_capacity(TASKS); for _ in 0..TASKS { diff --git a/tests-integration/tests/lazy_cell_test.rs b/tests-integration/tests/lazy_cell_test.rs index 9c1d4aed..e056eb93 100644 --- a/tests-integration/tests/lazy_cell_test.rs +++ b/tests-integration/tests/lazy_cell_test.rs @@ -17,13 +17,19 @@ use std::cell::Cell; use std::future::Ready; +use std::future::pending; +use std::future::poll_fn; +use std::future::ready; +use std::pin::pin; use std::rc::Rc; use std::sync::Arc; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; +use std::task::Poll; use asyncband::once::LazyCell; use tokio::sync::Notify; +use tokio::task::yield_now; struct DropPanic; @@ -61,7 +67,7 @@ async fn concurrent_force_runs_initializer_once() { move || { Box::pin(async move { attempts.fetch_add(1, Ordering::SeqCst); - tokio::task::yield_now().await; + yield_now().await; 42 }) } @@ -123,7 +129,7 @@ async fn from_future_does_not_poll_until_forced() { 42 } }); - let lazy = std::pin::pin!(lazy); + let lazy = pin!(lazy); assert_eq!(polls.load(Ordering::SeqCst), 0); assert_eq!(LazyCell::force_pin(lazy.as_ref()).await, &42); @@ -205,7 +211,7 @@ async fn dropping_cell_drops_suspended_attempt() { move || { Box::pin(async move { started.notify_one(); - std::future::pending::<()>().await; + pending::<()>().await; drop(held); 42 }) @@ -284,9 +290,9 @@ async fn initializer_poll_panic_permanently_poisons_cell() { async fn completed_future_drop_panic_permanently_poisons_cell() { let lazy = Arc::new(LazyCell::new(|| { let guard = DropPanic; - std::future::poll_fn(move |_| { + poll_fn(move |_| { let _ = &guard; - std::task::Poll::Ready(42) + Poll::Ready(42) }) })); @@ -307,7 +313,7 @@ async fn completed_future_drop_panic_permanently_poisons_cell() { #[tokio::test] async fn initializer_creation_panic_permanently_poisons_cell() { - let lazy = Arc::new(LazyCell::new(|| -> std::future::Ready { + let lazy = Arc::new(LazyCell::new(|| -> Ready { panic!("initializer creation panic") })); @@ -386,7 +392,7 @@ async fn initializer_need_not_be_sync() { } fn static_initializer() -> Ready { - std::future::ready(42) + ready(42) } static STATIC_LAZY: LazyCell> = LazyCell::new(static_initializer); @@ -402,11 +408,11 @@ async fn inline_future_supports_local_non_send_state() { let lazy = LazyCell::new({ let local = Rc::clone(&local); async move || { - tokio::task::yield_now().await; + yield_now().await; *local + 1 } }); - let mut lazy = std::pin::pin!(lazy); + let mut lazy = pin!(lazy); assert_eq!(*LazyCell::force_pin(lazy.as_ref()).await, 42); assert_eq!(LazyCell::get(&lazy), Some(&42)); @@ -431,7 +437,7 @@ async fn cancellation_preserves_inline_initialization_future() { 42 } }); - let lazy = std::pin::pin!(lazy); + let lazy = pin!(lazy); tokio::select! { biased; diff --git a/tests-integration/tests/mpmc_test/concurrency.rs b/tests-integration/tests/mpmc_test/concurrency.rs index ae20a747..db336be0 100644 --- a/tests-integration/tests/mpmc_test/concurrency.rs +++ b/tests-integration/tests/mpmc_test/concurrency.rs @@ -20,8 +20,9 @@ use std::time::Duration; use asyncband::mpmc; use tokio::task::JoinHandle; +use tokio::time::timeout; -use super::Receiver; +use crate::Receiver; const PRODUCERS: usize = 8; const CONSUMERS: usize = 8; @@ -52,7 +53,7 @@ where .collect::>(); drop(receiver); - let mut received = tokio::time::timeout(Duration::from_secs(10), async { + let mut received = timeout(Duration::from_secs(10), async { for producer in producers { producer.await.unwrap(); } diff --git a/tests-integration/tests/mpmc_test/notification.rs b/tests-integration/tests/mpmc_test/notification.rs index f81f8953..e5fffee5 100644 --- a/tests-integration/tests/mpmc_test/notification.rs +++ b/tests-integration/tests/mpmc_test/notification.rs @@ -26,7 +26,7 @@ use tests_integration::WakeCounter; use tests_integration::expect_ready; use tests_integration::poll_with; -use super::Receiver; +use crate::Receiver; #[derive(Debug)] enum NotifiedReceiver { @@ -39,7 +39,7 @@ fn receiver_notifications>( channel: impl Fn() -> (S, R), send: impl Fn(&S, usize), ) { - use NotifiedReceiver::*; + use crate::notification::NotifiedReceiver::*; for action in [Receive, Cancel, TakeValueThenCancel] { let (sender, receiver) = channel(); diff --git a/tests-integration/tests/mpsc_test/callbacks.rs b/tests-integration/tests/mpsc_test/callbacks.rs index fa6e1120..b522c5af 100644 --- a/tests-integration/tests/mpsc_test/callbacks.rs +++ b/tests-integration/tests/mpsc_test/callbacks.rs @@ -15,6 +15,9 @@ // specific language governing permissions and limitations // under the License. +use std::array; +use std::panic::AssertUnwindSafe; +use std::panic::catch_unwind; use std::sync::Arc; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; @@ -244,7 +247,7 @@ fn bounded_disconnect_finishes_cleanup_when_a_value_destructor_panics() { } let (tx, rx) = mpsc::bounded(3); - let drops = Arc::new(std::array::from_fn(|_| AtomicUsize::new(0))); + let drops = Arc::new(array::from_fn(|_| AtomicUsize::new(0))); for id in 0..3 { assert!( tx.try_send(Value { @@ -270,7 +273,7 @@ fn bounded_disconnect_finishes_cleanup_when_a_value_destructor_panics() { for (send, (waker, _)) in sends.iter_mut().zip(¬ifications) { assert!(poll_with(send.as_mut(), waker).is_pending()); } - assert!(std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| drop(rx))).is_err()); + assert!(catch_unwind(AssertUnwindSafe(|| drop(rx))).is_err()); for (_, wakes) in ¬ifications { assert_eq!(wakes.count(), 1); } diff --git a/tests-integration/tests/mpsc_test/concurrency.rs b/tests-integration/tests/mpsc_test/concurrency.rs index e77d0d71..7b753b71 100644 --- a/tests-integration/tests/mpsc_test/concurrency.rs +++ b/tests-integration/tests/mpsc_test/concurrency.rs @@ -15,8 +15,11 @@ // specific language governing permissions and limitations // under the License. +use std::array; use std::future::Future; +use std::future::poll_fn; use std::pin::Pin; +use std::pin::pin; use std::sync::Arc; use std::sync::Barrier; use std::sync::atomic::AtomicUsize; @@ -33,6 +36,8 @@ use tests_integration::WakeCounter; use tests_integration::poll_once; use tests_integration::poll_with; use tests_integration::test_runtime; +use tokio::sync::oneshot; +use tokio::task::yield_now; use tokio_test::assert_ok; #[test] @@ -54,7 +59,7 @@ fn publication_racing_with_close_drops_every_payload_once() { for _ in 0..if cfg!(miri) { 8 } else { 128 } { let (tx, rx) = mpsc::bounded(3); - let drops = Arc::new(std::array::from_fn(|_| AtomicUsize::new(0))); + let drops = Arc::new(array::from_fn(|_| AtomicUsize::new(0))); let start = Barrier::new(4); thread::scope(|scope| { for byte in 0..3 { @@ -297,12 +302,12 @@ fn unbounded_collects_from_multiple_producers() { #[cfg_attr(miri, ignore = "requires an OS-backed Tokio runtime")] async fn bounded_backpressure_progresses_on_an_executor() { let (tx, mut rx) = mpsc::bounded(1); - let (blocked_tx, blocked_rx) = tokio::sync::oneshot::channel(); + let (blocked_tx, blocked_rx) = oneshot::channel(); tx.send(1).await.unwrap(); let sender = tokio::spawn(async move { - let mut send = std::pin::pin!(tx.send(2)); - let first_poll = std::future::poll_fn(|cx| Poll::Ready(send.as_mut().poll(cx))).await; + let mut send = pin!(tx.send(2)); + let first_poll = poll_fn(|cx| Poll::Ready(send.as_mut().poll(cx))).await; assert!(first_poll.is_pending()); blocked_tx.send(()).unwrap(); send.await.unwrap(); @@ -325,22 +330,22 @@ async fn selection_preserves_messages_across_cancelled_receives() { tokio::spawn(async move { assert_ok!(tx2.send(1)); - tokio::task::yield_now().await; + yield_now().await; assert_ok!(tx1.send(2)); - tokio::task::yield_now().await; + yield_now().await; assert_ok!(tx2.send(3)); - tokio::task::yield_now().await; + yield_now().await; assert_ok!(tx3.send(4).await); - tokio::task::yield_now().await; + yield_now().await; assert_ok!(tx4.send(5).await); - tokio::task::yield_now().await; + yield_now().await; assert_ok!(tx3.send(6).await); - tokio::task::yield_now().await; + yield_now().await; drop((tx1, tx2)); }); diff --git a/tests-integration/tests/mpsc_test/reservation.rs b/tests-integration/tests/mpsc_test/reservation.rs index 80b44dd8..d9ea37db 100644 --- a/tests-integration/tests/mpsc_test/reservation.rs +++ b/tests-integration/tests/mpsc_test/reservation.rs @@ -17,6 +17,7 @@ use std::cell::Cell; use std::mem; +use std::thread; use asyncband::mpsc; use asyncband::mpsc::TryRecvError; @@ -139,7 +140,7 @@ fn receiver_drop_does_not_wait_for_held_or_forgotten_permits() { fn a_permit_can_publish_send_only_payloads_from_another_thread() { let (tx, mut rx) = mpsc::bounded(1); let permit = tx.try_reserve().unwrap(); - std::thread::scope(|scope| { + thread::scope(|scope| { scope .spawn(move || permit.send(Cell::new(42)).unwrap()) .join() @@ -154,7 +155,7 @@ fn concurrent_cancellation_preserves_capacity_and_message_order() { const MESSAGES: usize = if cfg!(miri) { 8 } else { 256 }; let (tx, mut rx) = mpsc::bounded(3); let mut out_of_order = 0; - std::thread::scope(|scope| { + thread::scope(|scope| { let mut workers = vec![]; for producer in 0..PRODUCERS { let tx = tx.clone(); @@ -164,7 +165,7 @@ fn concurrent_cancellation_preserves_capacity_and_message_order() { let permit = loop { match tx.try_reserve() { Ok(permit) => break permit, - Err(TrySendError::Full(())) => std::thread::yield_now(), + Err(TrySendError::Full(())) => thread::yield_now(), Err(TrySendError::Disconnected(())) => panic!("receiver is alive"), } }; @@ -186,7 +187,7 @@ fn concurrent_cancellation_preserves_capacity_and_message_order() { next[producer] += 1; count += 1; } - Err(TryRecvError::Empty) => std::thread::yield_now(), + Err(TryRecvError::Empty) => thread::yield_now(), Err(TryRecvError::Disconnected) => panic!("senders are alive"), } } diff --git a/tests-integration/tests/mutex_test.rs b/tests-integration/tests/mutex_test.rs index 91cac410..7f1c5f79 100644 --- a/tests-integration/tests/mutex_test.rs +++ b/tests-integration/tests/mutex_test.rs @@ -15,10 +15,14 @@ // specific language governing permissions and limitations // under the License. +use std::panic::catch_unwind; +use std::pin::pin; use std::sync::Arc; +use std::task::Poll; use asyncband::mutex::*; use tests_integration::poll_once; +use tokio::task::yield_now; #[test] fn test_try_lock_never_blocks() { @@ -71,12 +75,12 @@ async fn test_owned_guard_filter_map_failure() { fn test_guard_prevents_concurrent_access() { let mutex = Mutex::new(0); let guard = mutex.try_lock().unwrap(); - let mut waiting = std::pin::pin!(mutex.lock()); + let mut waiting = pin!(mutex.lock()); assert!(poll_once(waiting.as_mut()).is_pending()); drop(guard); - let std::task::Poll::Ready(second_guard) = poll_once(waiting.as_mut()) else { + let Poll::Ready(second_guard) = poll_once(waiting.as_mut()) else { panic!("queued lock should complete after the active guard drops"); }; assert_eq!(*second_guard, 0); @@ -89,7 +93,7 @@ fn test_lock_panic_safety() { let mutex = Arc::new(Mutex::new(0)); let mutex_clone = mutex.clone(); - let result = std::panic::catch_unwind(AssertUnwindSafe(move || { + let result = catch_unwind(AssertUnwindSafe(move || { let _guard = mutex_clone.try_lock().unwrap(); panic!("test panic"); })); @@ -175,7 +179,7 @@ async fn test_mapped_mutex_guard_send() { let guard = mutex_clone.lock().await; let mapped_guard = MutexGuard::map(guard, |data| &mut data.field1); - tokio::task::yield_now().await; + yield_now().await; *mapped_guard }); diff --git a/tests-integration/tests/once_cell_test.rs b/tests-integration/tests/once_cell_test.rs index f9303397..b01ce1e9 100644 --- a/tests-integration/tests/once_cell_test.rs +++ b/tests-integration/tests/once_cell_test.rs @@ -15,6 +15,7 @@ // specific language governing permissions and limitations // under the License. +use std::future::pending; use std::sync::Arc; use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicUsize; @@ -22,6 +23,7 @@ use std::sync::atomic::Ordering; use asyncband::once::OnceCell; use tests_integration::poll_once; +use tokio::sync::Barrier; struct DropFlag(Arc); @@ -50,7 +52,7 @@ async fn concurrent_callers_publish_one_value() { let cell = Arc::new(OnceCell::new()); let attempts = Arc::new(AtomicUsize::new(0)); - let start = Arc::new(tokio::sync::Barrier::new(TASKS + 1)); + let start = Arc::new(Barrier::new(TASKS + 1)); let mut tasks = Vec::with_capacity(TASKS); for value in 0..TASKS { @@ -79,7 +81,7 @@ async fn concurrent_callers_publish_one_value() { #[tokio::test] async fn cancelled_initialization_can_be_retried() { let cell = OnceCell::new(); - let mut first = Box::pin(cell.get_or_init(async || std::future::pending::().await)); + let mut first = Box::pin(cell.get_or_init(async || pending::().await)); assert!(poll_once(first.as_mut()).is_pending()); drop(first); diff --git a/tests-integration/tests/once_map_test.rs b/tests-integration/tests/once_map_test.rs index 991aba1e..ad9b56e8 100644 --- a/tests-integration/tests/once_map_test.rs +++ b/tests-integration/tests/once_map_test.rs @@ -25,12 +25,13 @@ use std::sync::atomic::Ordering; use asyncband::once::OnceMap; use tests_integration::poll_once; +use tokio::sync::oneshot; #[tokio::test] async fn concurrent_compute_runs_once() { let map = OnceMap::new(); let count = AtomicUsize::new(0); - let (release_tx, release_rx) = tokio::sync::oneshot::channel(); + let (release_tx, release_rx) = oneshot::channel(); let first = map.compute("key", async || { count.fetch_add(1, Ordering::SeqCst); @@ -195,8 +196,8 @@ async fn discard_releases_the_removed_key_and_value_after_growth() { #[tokio::test] async fn remove_while_computing_allows_a_new_generation() { let map = Arc::new(OnceMap::new()); - let (started_tx, started_rx) = tokio::sync::oneshot::channel(); - let (release_tx, release_rx) = tokio::sync::oneshot::channel(); + let (started_tx, started_rx) = oneshot::channel(); + let (release_tx, release_rx) = oneshot::channel(); let map_clone = map.clone(); let task = tokio::spawn(async move { diff --git a/tests-integration/tests/once_test.rs b/tests-integration/tests/once_test.rs index 622f746e..f33835db 100644 --- a/tests-integration/tests/once_test.rs +++ b/tests-integration/tests/once_test.rs @@ -15,12 +15,14 @@ // specific language governing permissions and limitations // under the License. +use std::future::pending; use std::sync::Arc; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; use asyncband::once::Once; use tests_integration::poll_once; +use tokio::sync::Barrier; #[tokio::test] async fn call_once_runs_only_one_initializer() { @@ -51,7 +53,7 @@ async fn concurrent_callers_run_one_initializer() { let once = Arc::new(Once::new()); let counter = Arc::new(AtomicUsize::new(0)); - let start = Arc::new(tokio::sync::Barrier::new(TASKS + 1)); + let start = Arc::new(Barrier::new(TASKS + 1)); let mut tasks = Vec::with_capacity(TASKS); for _ in 0..TASKS { @@ -79,7 +81,7 @@ async fn concurrent_callers_run_one_initializer() { #[tokio::test] async fn cancelled_initializer_can_be_retried() { let once = Once::new(); - let mut first = Box::pin(once.call_once(async || std::future::pending::<()>().await)); + let mut first = Box::pin(once.call_once(async || pending::<()>().await)); assert!(poll_once(first.as_mut()).is_pending()); drop(first); diff --git a/tests-integration/tests/oneshot_test/main.rs b/tests-integration/tests/oneshot_test/main.rs index 7dadc8e1..2d106cf0 100644 --- a/tests-integration/tests/oneshot_test/main.rs +++ b/tests-integration/tests/oneshot_test/main.rs @@ -34,10 +34,10 @@ use asyncband::blocking::FutureExt; use asyncband::oneshot; use asyncband::oneshot::TryRecvError; -use self::support::DropProbe; -use self::support::WakerProbe; -use self::support::spawn_named; -use self::support::spin_until; +use crate::support::DropProbe; +use crate::support::WakerProbe; +use crate::support::spawn_named; +use crate::support::spin_until; mod support; diff --git a/tests-integration/tests/oneshot_test/support.rs b/tests-integration/tests/oneshot_test/support.rs index 0b67c36b..a58c9685 100644 --- a/tests-integration/tests/oneshot_test/support.rs +++ b/tests-integration/tests/oneshot_test/support.rs @@ -29,6 +29,7 @@ use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; use std::task::Wake; use std::task::Waker; +use std::thread; use std::time::Duration; use std::time::Instant; @@ -92,12 +93,12 @@ impl Wake for WakerProbe { } } -pub(super) fn spawn_named(name: &str, f: F) -> std::thread::JoinHandle +pub(super) fn spawn_named(name: &str, f: F) -> thread::JoinHandle where F: FnOnce() -> T + Send + 'static, T: Send + 'static, { - std::thread::Builder::new() + thread::Builder::new() .name(name.to_owned()) .spawn(f) .unwrap() @@ -118,7 +119,7 @@ where assert!(Instant::now() < deadline, "timed out waiting for {label}"); if spins % 64 == 0 { - std::thread::yield_now(); + thread::yield_now(); } else { spin_loop(); } diff --git a/tests-integration/tests/phaser_test.rs b/tests-integration/tests/phaser_test.rs index af81580d..aaef6e91 100644 --- a/tests-integration/tests/phaser_test.rs +++ b/tests-integration/tests/phaser_test.rs @@ -15,8 +15,10 @@ // specific language governing permissions and limitations // under the License. +use std::array; use std::panic; use std::task::Poll; +use std::thread; use asyncband::blocking::FutureExt; use asyncband::phaser::Phaser; @@ -24,6 +26,8 @@ use tests_integration::WakeCounter; use tests_integration::poll_once; use tests_integration::poll_with; use tests_integration::waker_on_drop; +use tokio::sync::oneshot; +use tokio::task::yield_now; #[test] fn batch_registration_joins_one_observed_phase() { @@ -621,7 +625,7 @@ async fn participant_can_wait_from_a_spawned_task() { let first_wait = tokio::spawn(async move { first.wait().await }); - tokio::task::yield_now().await; + yield_now().await; let phase = second.arrive().unwrap(); assert_eq!(first_wait.await.unwrap().unwrap(), phaser.phase()); assert_ne!(phase, phaser.phase()); @@ -637,7 +641,7 @@ async fn observer_waits_without_becoming_a_party() { let observer_phaser = phaser.clone(); let observer = tokio::spawn(async move { observer_phaser.wait(observed).await }); - tokio::task::yield_now().await; + yield_now().await; assert_eq!(phaser.registered_parties(), 2); first.arrive().unwrap(); second.deregister().unwrap(); @@ -652,9 +656,9 @@ fn arrivals_publish_each_workers_writes_across_threads() { use std::sync::atomic::Ordering; let phaser = Phaser::new(); - let values = std::array::from_fn::<_, 4, _>(|_| AtomicUsize::new(0)); + let values = array::from_fn::<_, 4, _>(|_| AtomicUsize::new(0)); let participants = phaser.register(values.len()).unwrap(); - std::thread::scope(|scope| { + thread::scope(|scope| { for (id, mut participant) in participants.enumerate() { let values = &values; scope.spawn(move || { @@ -683,7 +687,7 @@ async fn a_failed_task_can_close_the_group_without_reporting_phase_completion() let mut worker = phaser.register_one().unwrap(); let failing = phaser.register_one().unwrap(); let observed = phaser.phase(); - let (arrived, arrival) = tokio::sync::oneshot::channel(); + let (arrived, arrival) = oneshot::channel(); let task = tokio::spawn(async move { worker.arrive().unwrap(); arrived.send(()).unwrap(); diff --git a/tests-integration/tests/pool_test/acquire.rs b/tests-integration/tests/pool_test/acquire.rs index 39276acc..d8e3ece6 100644 --- a/tests-integration/tests/pool_test/acquire.rs +++ b/tests-integration/tests/pool_test/acquire.rs @@ -16,6 +16,7 @@ // under the License. use std::future::Future; +use std::mem; use std::pin::pin; use std::sync::Arc; use std::task::Context; @@ -27,8 +28,8 @@ use asyncband::pool::bounded::Pool; use asyncband::pool::bounded::PoolConfig; use tests_integration::WakeCounter; -use super::support::Manager; -use super::support::ManagerError; +use crate::support::Manager; +use crate::support::ManagerError; fn ready(future: impl Future>) -> T { let wakes = Arc::new(WakeCounter::default()); @@ -81,8 +82,8 @@ fn cancel_waiter(return_before_cancel: bool) { drop(held); // Cancel a notified waiter without requiring FIFO notification order. if first_wakes.count() == 0 { - std::mem::swap(&mut first, &mut next); - std::mem::swap(&mut first_wakes, &mut next_wakes); + mem::swap(&mut first, &mut next); + mem::swap(&mut first_wakes, &mut next_wakes); } assert!(first_wakes.count() > 0); // Cancel the notified future without polling it to retrieve its permit. diff --git a/tests-integration/tests/pool_test/behavior.rs b/tests-integration/tests/pool_test/behavior.rs index 9d68269f..0c43659c 100644 --- a/tests-integration/tests/pool_test/behavior.rs +++ b/tests-integration/tests/pool_test/behavior.rs @@ -25,7 +25,7 @@ use asyncband::pool::QueueStrategy; use asyncband::pool::bounded; use asyncband::pool::unbounded; -use super::support::Manager; +use crate::support::Manager; #[test] #[should_panic(expected = "bounded pool max_size must be greater than zero")] diff --git a/tests-integration/tests/pool_test/recycle.rs b/tests-integration/tests/pool_test/recycle.rs index d877cc61..44020196 100644 --- a/tests-integration/tests/pool_test/recycle.rs +++ b/tests-integration/tests/pool_test/recycle.rs @@ -21,9 +21,9 @@ use tests_integration::expect_ready; use tests_integration::poll_once; use tests_integration::poll_with; -use super::support::Manager; -use super::support::ManagerError; -use super::support::ready; +use crate::support::Manager; +use crate::support::ManagerError; +use crate::support::ready; // Both pool variants promise the same object lifecycle during recycle cancellation. macro_rules! recycle_contract { diff --git a/tests-integration/tests/pool_test/replenish.rs b/tests-integration/tests/pool_test/replenish.rs index b0a351dc..facc7dbe 100644 --- a/tests-integration/tests/pool_test/replenish.rs +++ b/tests-integration/tests/pool_test/replenish.rs @@ -24,9 +24,9 @@ use tests_integration::expect_ready; use tests_integration::poll_once; use tests_integration::poll_with; -use super::support::Manager; -use super::support::ManagerError; -use super::support::ready; +use crate::support::Manager; +use crate::support::ManagerError; +use crate::support::ready; #[test] fn targets_account_for_idle_objects_and_checked_out_capacity() { diff --git a/tests-integration/tests/rwlock_test.rs b/tests-integration/tests/rwlock_test.rs index 226e2f42..f5518655 100644 --- a/tests-integration/tests/rwlock_test.rs +++ b/tests-integration/tests/rwlock_test.rs @@ -15,11 +15,14 @@ // specific language governing permissions and limitations // under the License. +use std::future::pending; use std::num::NonZeroUsize; use std::sync::Arc; use asyncband::rwlock::*; use tests_integration::poll_once; +use tokio::sync::Barrier; +use tokio::task::yield_now; use tokio_test::assert_pending; use tokio_test::assert_ready; @@ -68,7 +71,7 @@ async fn concurrent_readers_and_writers_preserve_values() { const WRITERS: usize = 10; let rwlock = Arc::new(RwLock::new(0)); - let start = Arc::new(tokio::sync::Barrier::new(READERS + WRITERS + 1)); + let start = Arc::new(Barrier::new(READERS + WRITERS + 1)); let mut readers = Vec::with_capacity(READERS); let mut writers = Vec::with_capacity(WRITERS); @@ -78,7 +81,7 @@ async fn concurrent_readers_and_writers_preserve_values() { readers.push(tokio::spawn(async move { start.wait().await; let value = *rwlock.read().await; - tokio::task::yield_now().await; + yield_now().await; value })); } @@ -90,7 +93,7 @@ async fn concurrent_readers_and_writers_preserve_values() { start.wait().await; let mut guard = rwlock.write().await; *guard += 1; - tokio::task::yield_now().await; + yield_now().await; })); } @@ -361,7 +364,7 @@ fn cancelled_mapped_reader_admits_a_queued_writer() { let mut reader = Box::pin(async { let _mapped = RwLockReadGuard::map(rwlock.read().await, |values| &values[0]); - std::future::pending::<()>().await; + pending::<()>().await; }); assert_pending!(poll_once(reader.as_mut())); let mut writer = Box::pin(rwlock.write()); @@ -379,7 +382,7 @@ fn cancelled_mapped_writer_admits_a_queued_reader() { let mut writer = Box::pin(async { let mut mapped = RwLockWriteGuard::map(rwlock.write().await, |values| &mut values[0]); *mapped = 10; - std::future::pending::<()>().await; + pending::<()>().await; }); assert_pending!(poll_once(writer.as_mut())); let mut reader = Box::pin(rwlock.read()); @@ -417,11 +420,11 @@ async fn aborted_task_releases_its_owned_mapped_rwlock_guard() { *mapped = 10; let task = tokio::spawn(async move { let _mapped = mapped; - std::future::pending::<()>().await; + pending::<()>().await; }); assert!(rwlock.try_read().is_none()); - tokio::task::yield_now().await; + yield_now().await; task.abort(); assert!(task.await.unwrap_err().is_cancelled()); assert_eq!(*rwlock.try_read().unwrap(), [10, 2]); diff --git a/tests-integration/tests/semaphore_test.rs b/tests-integration/tests/semaphore_test.rs index 02431f3c..db1903d9 100644 --- a/tests-integration/tests/semaphore_test.rs +++ b/tests-integration/tests/semaphore_test.rs @@ -15,6 +15,8 @@ // specific language governing permissions and limitations // under the License. +use std::panic::AssertUnwindSafe; +use std::panic::catch_unwind; use std::pin::pin; use std::sync::Arc; use std::task::Context; @@ -82,7 +84,7 @@ fn maximum_capacity_can_be_acquired_and_returned() { #[test] fn release_overflow_preserves_permits() { let s = Semaphore::new(usize::MAX); - let result = std::panic::catch_unwind(|| s.release(1)); + let result = catch_unwind(|| s.release(1)); assert!(result.is_err()); assert_eq!(s.available_permits(), usize::MAX); @@ -100,7 +102,7 @@ fn merge_overflow_panics_without_losing_borrowed_permits() { s.release(1); let second = s.try_acquire(1).unwrap(); - let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { + let result = catch_unwind(AssertUnwindSafe(|| { first.merge(second); })); @@ -117,7 +119,7 @@ fn merge_overflow_panics_without_losing_owned_permits() { s.release(1); let second = s.clone().try_acquire_owned(1).unwrap(); - let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { + let result = catch_unwind(AssertUnwindSafe(|| { first.merge(second); })); diff --git a/tests-integration/tests/shutdown_test.rs b/tests-integration/tests/shutdown_test.rs index 6ab4d211..8e5190fe 100644 --- a/tests-integration/tests/shutdown_test.rs +++ b/tests-integration/tests/shutdown_test.rs @@ -16,6 +16,7 @@ // under the License. use std::future::pending; +use std::future::ready; use std::pin::pin; use asyncband::blocking::FutureExt; @@ -122,7 +123,7 @@ fn test_disabled_select_branch_does_not_request_shutdown() { tokio::select! { _ = shutdown, if false => unreachable!(), - _ = std::future::ready(()) => {} + _ = ready(()) => {} } assert!(!watch.is_shutdown_requested()); diff --git a/tests-integration/tests/singleflight_test.rs b/tests-integration/tests/singleflight_test.rs index 284a51b4..961d5d3d 100644 --- a/tests-integration/tests/singleflight_test.rs +++ b/tests-integration/tests/singleflight_test.rs @@ -28,6 +28,7 @@ use std::task::Poll; use asyncband::singleflight::Group; use tests_integration::assert_completes_without_deadlock; use tests_integration::poll_once; +use tokio::sync::oneshot; #[tokio::test] async fn supports_non_clone_key() { @@ -43,7 +44,7 @@ async fn supports_non_clone_key() { async fn concurrent_work_is_coalesced() { let group = Group::new(); let counter = AtomicUsize::new(0); - let (release_tx, release_rx) = tokio::sync::oneshot::channel(); + let (release_tx, release_rx) = oneshot::channel(); let leader = group.work("key", || async { counter.fetch_add(1, Ordering::SeqCst); @@ -77,7 +78,7 @@ async fn concurrent_work_is_coalesced() { #[tokio::test] async fn pending_work_does_not_block_other_keys() { let group = Group::new(); - let (release_tx, release_rx) = tokio::sync::oneshot::channel(); + let (release_tx, release_rx) = oneshot::channel(); let first = group.work("key1", || async { release_rx.await.unwrap(); @@ -96,8 +97,8 @@ async fn pending_work_does_not_block_other_keys() { async fn forget_detaches_in_flight_work() { let group = Group::new(); let counter = AtomicUsize::new(0); - let (first_release_tx, first_release_rx) = tokio::sync::oneshot::channel(); - let (second_release_tx, second_release_rx) = tokio::sync::oneshot::channel(); + let (first_release_tx, first_release_rx) = oneshot::channel(); + let (second_release_tx, second_release_rx) = oneshot::channel(); let first = group.work("key".to_owned(), || async { counter.fetch_add(1, Ordering::SeqCst); @@ -142,7 +143,7 @@ async fn try_work_returns_value_without_caching_it() { async fn concurrent_try_work_is_coalesced() { let group = Group::new(); let counter = AtomicUsize::new(0); - let (release_tx, release_rx) = tokio::sync::oneshot::channel(); + let (release_tx, release_rx) = oneshot::channel(); let leader = group.try_work("key", || async { counter.fetch_add(1, Ordering::SeqCst); @@ -211,7 +212,7 @@ fn duplicate_key_destructor_can_forget_another_key() { assert_completes_without_deadlock(|| { for fallible in [false, true] { let group = Rc::new(Group::new()); - let (release_tx, release_rx) = tokio::sync::oneshot::channel(); + let (release_tx, release_rx) = oneshot::channel(); let mut leader = pin!(group.work( Key { value: 7, diff --git a/tests-integration/tests/spmc_test/concurrency.rs b/tests-integration/tests/spmc_test/concurrency.rs index d44ba4d1..30c3558f 100644 --- a/tests-integration/tests/spmc_test/concurrency.rs +++ b/tests-integration/tests/spmc_test/concurrency.rs @@ -21,6 +21,7 @@ use std::time::Duration; use asyncband::spmc; use tokio::sync::Barrier; use tokio::task::JoinHandle; +use tokio::time::timeout; const CONSUMERS: usize = 8; const TOTAL: usize = 2_048; @@ -29,7 +30,7 @@ async fn assert_delivered_exactly_once( producer: JoinHandle<()>, consumers: Vec>>, ) { - tokio::time::timeout(Duration::from_secs(10), async { + timeout(Duration::from_secs(10), async { producer.await.unwrap(); let mut received = Vec::with_capacity(TOTAL); for consumer in consumers { diff --git a/tests-integration/tests/spmc_test/notification.rs b/tests-integration/tests/spmc_test/notification.rs index 51f0e0fb..5b654ced 100644 --- a/tests-integration/tests/spmc_test/notification.rs +++ b/tests-integration/tests/spmc_test/notification.rs @@ -30,7 +30,7 @@ use tests_integration::expect_ready; use tests_integration::poll_once; use tests_integration::poll_with; -use super::DropSpy; +use crate::DropSpy; #[test] fn bounded_one_send_wakes_one_of_eight_receivers_and_cancellation_hands_off() { diff --git a/tests-integration/tests/traits_test.rs b/tests-integration/tests/traits_test.rs index 47972d9d..f5dc0cdb 100644 --- a/tests-integration/tests/traits_test.rs +++ b/tests-integration/tests/traits_test.rs @@ -16,12 +16,16 @@ // under the License. use std::cell::Cell; +use std::convert::Infallible; +use std::fmt; +use std::future::Ready; use std::marker::PhantomPinned; use std::panic::RefUnwindSafe; use std::panic::UnwindSafe; +use std::sync::MutexGuard as StdMutexGuard; use asyncband::barrier::Barrier; -use asyncband::broadcast; +use asyncband::broadcast::mpmc as broadcast_mpmc; use asyncband::completion; use asyncband::condvar::Condvar; use asyncband::event::AutoResetEvent; @@ -40,9 +44,10 @@ use asyncband::phaser::Closed; use asyncband::phaser::Phaser; use asyncband::phaser::PhaserParticipant; use asyncband::phaser::PhaserParticipants; -use asyncband::pool; use asyncband::pool::ManageObject; use asyncband::pool::ObjectStatus; +use asyncband::pool::bounded as bounded_pool; +use asyncband::pool::unbounded as unbounded_pool; use asyncband::rwlock::MappedRwLockReadGuard; use asyncband::rwlock::MappedRwLockWriteGuard; use asyncband::rwlock::OwnedMappedRwLockWriteGuard; @@ -63,7 +68,7 @@ struct PoolManager; impl ManageObject for PoolManager { type Object = i64; - type Error = std::convert::Infallible; + type Error = Infallible; async fn create(&self) -> Result { Ok(0) @@ -90,7 +95,7 @@ fn public_types_are_send_and_sync() { assert_send_and_sync::>(); assert_send_and_sync::>(); assert_send_and_sync::(); - assert_send_and_sync::>>(); + assert_send_and_sync::>>(); assert_send_and_sync::(); assert_send_and_sync::>(); assert_send_and_sync::>(); @@ -107,24 +112,24 @@ fn public_types_are_send_and_sync() { assert_send_and_sync::>(); assert_send_and_sync::>(); assert_send_and_sync::>(); - assert_send_and_sync::>(); - assert_send_and_sync::>(); - assert_send_and_sync::>(); - assert_send_and_sync::>(); - assert_send_and_sync::(); - assert_send_and_sync::(); - assert_send_and_sync::>(); + assert_send_and_sync::>(); + assert_send_and_sync::>(); + assert_send_and_sync::>(); + assert_send_and_sync::>(); + assert_send_and_sync::(); + assert_send_and_sync::(); + assert_send_and_sync::>(); assert_send_and_sync::>(); assert_send_and_sync::>(); assert_send_and_sync::(); assert_send_and_sync::(); assert_send_and_sync::(); assert_send_and_sync::(); - assert_send_and_sync::>(); - assert_send_and_sync::>(); - assert_send_and_sync::>(); - assert_send_and_sync::>(); - assert_send_and_sync::>>(); + assert_send_and_sync::>(); + assert_send_and_sync::>(); + assert_send_and_sync::>(); + assert_send_and_sync::>(); + assert_send_and_sync::>>(); assert_send_and_sync::>(); assert_send_and_sync::>(); assert_send_and_sync::>(); @@ -150,13 +155,13 @@ fn movable_public_types_are_send() { fn assert_send() {} fn assert_send_value(_: T) {} - assert_send::>>(); - assert_send::>>(); + assert_send::>>(); + assert_send::>>(); assert_send::>>(); assert_send::>>(); assert_send::>(); assert_send::>(); - assert_send::>>(); + assert_send::>>(); let (_tx, mut rx) = watch::channel(0); assert_send_value(rx.changed()); @@ -186,7 +191,7 @@ fn public_types_are_unpin() { assert_unpin::>(); assert_unpin::(); assert_unpin::(); - assert_unpin::>>(); + assert_unpin::>>(); assert_unpin::(); assert_unpin::>(); assert_unpin::>(); @@ -202,13 +207,13 @@ fn public_types_are_unpin() { assert_unpin::>(); assert_unpin::>(); assert_unpin::>(); - assert_unpin::>(); - assert_unpin::>(); - assert_unpin::>(); - assert_unpin::>(); - assert_unpin::(); - assert_unpin::(); - assert_unpin::>(); + assert_unpin::>(); + assert_unpin::>(); + assert_unpin::>(); + assert_unpin::>(); + assert_unpin::(); + assert_unpin::(); + assert_unpin::>(); assert_unpin::>(); assert_unpin::>(); assert_unpin::>(); @@ -217,10 +222,10 @@ fn public_types_are_unpin() { assert_unpin::(); assert_unpin::(); assert_unpin::(); - assert_unpin::>(); - assert_unpin::>(); - assert_unpin::>(); - assert_unpin::>(); + assert_unpin::>(); + assert_unpin::>(); + assert_unpin::>(); + assert_unpin::>(); assert_unpin::>(); assert_unpin::>(); assert_unpin::>(); @@ -274,8 +279,8 @@ fn mpsc_endpoints_keep_legacy_traits_regardless_of_payload() { #[test] fn unbounded_manual_manager_traits_do_not_depend_on_the_object() { fn assert_copy() {} - fn assert_debug() {} + fn assert_debug() {} - assert_copy::>(); - assert_debug::>(); + assert_copy::>(); + assert_debug::>(); } diff --git a/tests-integration/tests/watch_test.rs b/tests-integration/tests/watch_test.rs index d4e5d2e3..087f4a4e 100644 --- a/tests-integration/tests/watch_test.rs +++ b/tests-integration/tests/watch_test.rs @@ -15,6 +15,8 @@ // specific language governing permissions and limitations // under the License. +use std::panic::AssertUnwindSafe; +use std::panic::catch_unwind; use std::sync::Arc; use std::sync::atomic::AtomicBool; use std::sync::atomic::Ordering; @@ -110,9 +112,7 @@ fn panicking_clone_leaves_the_update_unseen() { .unwrap(); panic_next.store(true, Ordering::Relaxed); - let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { - FutureExt::block_on(rx.recv()) - })); + let result = catch_unwind(AssertUnwindSafe(|| FutureExt::block_on(rx.recv()))); assert!(result.is_err()); assert_eq!(rx.has_changed(), Ok(true)); diff --git a/xtask/src/main.rs b/xtask/src/main.rs index a047a4f4..a8526486 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -24,6 +24,7 @@ use clap::Parser; use clap::Subcommand; use semver::Version; use serde::Deserialize; +use ureq::Agent; const PACKAGE_NAME: &str = "asyncband"; // cargo-semver-checks reserves exit code 100 for completed checks that found deny-level violations. @@ -316,8 +317,8 @@ fn command_status(mut cmd: StdCommand) -> ExitStatus { } fn find_latest_release() -> Option { - let agent = ureq::Agent::from( - ureq::Agent::config_builder() + let agent = Agent::from( + Agent::config_builder() .timeout_global(Some(Duration::from_secs(10))) .build(), ); From 87319b2de7004ca9bf80fbf4c9c4d5632e93350e Mon Sep 17 00:00:00 2001 From: tison Date: Sun, 11 Oct 2026 13:39:38 +0100 Subject: [PATCH 2/8] style: preserve local public re-exports --- AGENTS.md | 2 ++ asyncband/src/broadcast/mpmc/mod.rs | 18 +++++++++--------- asyncband/src/event/mod.rs | 4 ++-- asyncband/src/mpmc/mod.rs | 22 +++++++++++----------- asyncband/src/mpsc/bounded/mod.rs | 6 +++--- asyncband/src/mpsc/mod.rs | 22 +++++++++++----------- asyncband/src/mpsc/unbounded/mod.rs | 4 ++-- asyncband/src/once/mod.rs | 8 ++++---- asyncband/src/oneshot/mod.rs | 12 ++++++------ asyncband/src/pool/mod.rs | 10 +++++----- asyncband/src/rwlock/mod.rs | 16 ++++++++-------- asyncband/src/spmc/mod.rs | 20 ++++++++++---------- asyncband/src/watch/mod.rs | 4 ++-- 13 files changed, 75 insertions(+), 73 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 3029eabb..767b89a7 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -35,6 +35,8 @@ Use imports for referenced symbols. Keep a short module qualifier or use an expl Start ordinary intra-crate imports at `crate`; avoid explicit `super::...` imports and qualified paths. Reserve `use super::*` for test modules. +Keep `pub use self::...` when re-exporting a module's own children as its public API. + ## Waker Contract - Allow normal executor `Waker::clone` inside short state critical sections. Custom clone panic recovery and reentrancy are not general guarantees; do not require them in reviews unless an explicit local contract does. diff --git a/asyncband/src/broadcast/mpmc/mod.rs b/asyncband/src/broadcast/mpmc/mod.rs index dcd502d7..b5eb4afd 100644 --- a/asyncband/src/broadcast/mpmc/mod.rs +++ b/asyncband/src/broadcast/mpmc/mod.rs @@ -43,12 +43,12 @@ mod common; mod error; mod unbounded; -pub use crate::broadcast::mpmc::bounded::BoundedReceiver; -pub use crate::broadcast::mpmc::bounded::BoundedSender; -pub use crate::broadcast::mpmc::bounded::bounded; -pub use crate::broadcast::mpmc::error::RecvError; -pub use crate::broadcast::mpmc::error::TryRecvError; -pub use crate::broadcast::mpmc::error::TrySendError; -pub use crate::broadcast::mpmc::unbounded::UnboundedReceiver; -pub use crate::broadcast::mpmc::unbounded::UnboundedSender; -pub use crate::broadcast::mpmc::unbounded::unbounded; +pub use self::bounded::BoundedReceiver; +pub use self::bounded::BoundedSender; +pub use self::bounded::bounded; +pub use self::error::RecvError; +pub use self::error::TryRecvError; +pub use self::error::TrySendError; +pub use self::unbounded::UnboundedReceiver; +pub use self::unbounded::UnboundedSender; +pub use self::unbounded::unbounded; diff --git a/asyncband/src/event/mod.rs b/asyncband/src/event/mod.rs index 5372f905..8f94320f 100644 --- a/asyncband/src/event/mod.rs +++ b/asyncband/src/event/mod.rs @@ -31,5 +31,5 @@ mod auto_reset; mod manual_reset; -pub use crate::event::auto_reset::AutoResetEvent; -pub use crate::event::manual_reset::ManualResetEvent; +pub use self::auto_reset::AutoResetEvent; +pub use self::manual_reset::ManualResetEvent; diff --git a/asyncband/src/mpmc/mod.rs b/asyncband/src/mpmc/mod.rs index 86daf1f3..ebb03a0c 100644 --- a/asyncband/src/mpmc/mod.rs +++ b/asyncband/src/mpmc/mod.rs @@ -27,14 +27,14 @@ mod error; mod queue; mod unbounded; -pub use crate::mpmc::bounded::BoundedReceiver; -pub use crate::mpmc::bounded::BoundedSender; -pub use crate::mpmc::bounded::Permit; -pub use crate::mpmc::bounded::bounded; -pub use crate::mpmc::error::RecvError; -pub use crate::mpmc::error::SendError; -pub use crate::mpmc::error::TryRecvError; -pub use crate::mpmc::error::TrySendError; -pub use crate::mpmc::unbounded::UnboundedReceiver; -pub use crate::mpmc::unbounded::UnboundedSender; -pub use crate::mpmc::unbounded::unbounded; +pub use self::bounded::BoundedReceiver; +pub use self::bounded::BoundedSender; +pub use self::bounded::Permit; +pub use self::bounded::bounded; +pub use self::error::RecvError; +pub use self::error::SendError; +pub use self::error::TryRecvError; +pub use self::error::TrySendError; +pub use self::unbounded::UnboundedReceiver; +pub use self::unbounded::UnboundedSender; +pub use self::unbounded::unbounded; diff --git a/asyncband/src/mpsc/bounded/mod.rs b/asyncband/src/mpsc/bounded/mod.rs index 962c8d25..a1e5abfc 100644 --- a/asyncband/src/mpsc/bounded/mod.rs +++ b/asyncband/src/mpsc/bounded/mod.rs @@ -30,9 +30,9 @@ use crate::mpsc::TrySendError; mod receiver; mod sender; -pub use crate::mpsc::bounded::receiver::BoundedReceiver; -pub use crate::mpsc::bounded::sender::BoundedSender; -pub use crate::mpsc::bounded::sender::Permit; +pub use self::receiver::BoundedReceiver; +pub use self::sender::BoundedSender; +pub use self::sender::Permit; /// Creates a bounded mpsc channel with room for `buffer` queued messages. /// diff --git a/asyncband/src/mpsc/mod.rs b/asyncband/src/mpsc/mod.rs index 21e623b5..bad23f06 100644 --- a/asyncband/src/mpsc/mod.rs +++ b/asyncband/src/mpsc/mod.rs @@ -25,14 +25,14 @@ mod bounded; mod error; mod unbounded; -pub use crate::mpsc::bounded::BoundedReceiver; -pub use crate::mpsc::bounded::BoundedSender; -pub use crate::mpsc::bounded::Permit; -pub use crate::mpsc::bounded::bounded; -pub use crate::mpsc::error::RecvError; -pub use crate::mpsc::error::SendError; -pub use crate::mpsc::error::TryRecvError; -pub use crate::mpsc::error::TrySendError; -pub use crate::mpsc::unbounded::UnboundedReceiver; -pub use crate::mpsc::unbounded::UnboundedSender; -pub use crate::mpsc::unbounded::unbounded; +pub use self::bounded::BoundedReceiver; +pub use self::bounded::BoundedSender; +pub use self::bounded::Permit; +pub use self::bounded::bounded; +pub use self::error::RecvError; +pub use self::error::SendError; +pub use self::error::TryRecvError; +pub use self::error::TrySendError; +pub use self::unbounded::UnboundedReceiver; +pub use self::unbounded::UnboundedSender; +pub use self::unbounded::unbounded; diff --git a/asyncband/src/mpsc/unbounded/mod.rs b/asyncband/src/mpsc/unbounded/mod.rs index 23f2284a..086f1807 100644 --- a/asyncband/src/mpsc/unbounded/mod.rs +++ b/asyncband/src/mpsc/unbounded/mod.rs @@ -28,8 +28,8 @@ mod buffer; mod receiver; mod sender; -pub use crate::mpsc::unbounded::receiver::UnboundedReceiver; -pub use crate::mpsc::unbounded::sender::UnboundedSender; +pub use self::receiver::UnboundedReceiver; +pub use self::sender::UnboundedSender; /// Creates an unbounded mpsc channel. Sending never waits for capacity. /// diff --git a/asyncband/src/once/mod.rs b/asyncband/src/once/mod.rs index 3a814966..770d538d 100644 --- a/asyncband/src/once/mod.rs +++ b/asyncband/src/once/mod.rs @@ -41,10 +41,10 @@ mod once_cell; mod once_map; #[cfg(feature = "lazy-cell")] -pub use crate::once::lazy_cell::LazyCell; +pub use self::lazy_cell::LazyCell; #[cfg(feature = "once")] -pub use crate::once::once::Once; +pub use self::once::Once; #[cfg(feature = "once-cell")] -pub use crate::once::once_cell::OnceCell; +pub use self::once_cell::OnceCell; #[cfg(feature = "once-map")] -pub use crate::once::once_map::OnceMap; +pub use self::once_map::OnceMap; diff --git a/asyncband/src/oneshot/mod.rs b/asyncband/src/oneshot/mod.rs index f53242ab..7859d7bc 100644 --- a/asyncband/src/oneshot/mod.rs +++ b/asyncband/src/oneshot/mod.rs @@ -99,12 +99,12 @@ use std::sync::atomic::fence; use std::task::Poll; use std::task::Waker; -pub use crate::oneshot::receiver::Receiver; -pub use crate::oneshot::receiver::Recv; -pub use crate::oneshot::receiver::RecvError; -pub use crate::oneshot::receiver::TryRecvError; -pub use crate::oneshot::sender::SendError; -pub use crate::oneshot::sender::Sender; +pub use self::receiver::Receiver; +pub use self::receiver::Recv; +pub use self::receiver::RecvError; +pub use self::receiver::TryRecvError; +pub use self::sender::SendError; +pub use self::sender::Sender; #[cfg(test)] mod tests; diff --git a/asyncband/src/pool/mod.rs b/asyncband/src/pool/mod.rs index afa6e77e..b9c05a00 100644 --- a/asyncband/src/pool/mod.rs +++ b/asyncband/src/pool/mod.rs @@ -214,8 +214,8 @@ mod state; pub mod bounded; pub mod unbounded; -pub use crate::pool::common::ManageObject; -pub use crate::pool::common::ObjectStatus; -pub use crate::pool::common::QueueStrategy; -pub use crate::pool::common::RecycleCancelledStrategy; -pub use crate::pool::common::RetainResult; +pub use self::common::ManageObject; +pub use self::common::ObjectStatus; +pub use self::common::QueueStrategy; +pub use self::common::RecycleCancelledStrategy; +pub use self::common::RetainResult; diff --git a/asyncband/src/rwlock/mod.rs b/asyncband/src/rwlock/mod.rs index 4e032710..a806d036 100644 --- a/asyncband/src/rwlock/mod.rs +++ b/asyncband/src/rwlock/mod.rs @@ -116,14 +116,14 @@ mod owned_write_guard; mod read_guard; mod write_guard; -pub use crate::rwlock::mapped_read_guard::MappedRwLockReadGuard; -pub use crate::rwlock::mapped_write_guard::MappedRwLockWriteGuard; -pub use crate::rwlock::owned_mapped_read_guard::OwnedMappedRwLockReadGuard; -pub use crate::rwlock::owned_mapped_write_guard::OwnedMappedRwLockWriteGuard; -pub use crate::rwlock::owned_read_guard::OwnedRwLockReadGuard; -pub use crate::rwlock::owned_write_guard::OwnedRwLockWriteGuard; -pub use crate::rwlock::read_guard::RwLockReadGuard; -pub use crate::rwlock::write_guard::RwLockWriteGuard; +pub use self::mapped_read_guard::MappedRwLockReadGuard; +pub use self::mapped_write_guard::MappedRwLockWriteGuard; +pub use self::owned_mapped_read_guard::OwnedMappedRwLockReadGuard; +pub use self::owned_mapped_write_guard::OwnedMappedRwLockWriteGuard; +pub use self::owned_read_guard::OwnedRwLockReadGuard; +pub use self::owned_write_guard::OwnedRwLockWriteGuard; +pub use self::read_guard::RwLockReadGuard; +pub use self::write_guard::RwLockWriteGuard; /// A value with fair, asynchronous shared or exclusive access. /// diff --git a/asyncband/src/spmc/mod.rs b/asyncband/src/spmc/mod.rs index 5604b4b9..eed5ace4 100644 --- a/asyncband/src/spmc/mod.rs +++ b/asyncband/src/spmc/mod.rs @@ -99,13 +99,13 @@ mod error; mod queue; mod unbounded; -pub use crate::spmc::bounded::BoundedReceiver; -pub use crate::spmc::bounded::BoundedSender; -pub use crate::spmc::bounded::bounded; -pub use crate::spmc::error::RecvError; -pub use crate::spmc::error::SendError; -pub use crate::spmc::error::TryRecvError; -pub use crate::spmc::error::TrySendError; -pub use crate::spmc::unbounded::UnboundedReceiver; -pub use crate::spmc::unbounded::UnboundedSender; -pub use crate::spmc::unbounded::unbounded; +pub use self::bounded::BoundedReceiver; +pub use self::bounded::BoundedSender; +pub use self::bounded::bounded; +pub use self::error::RecvError; +pub use self::error::SendError; +pub use self::error::TryRecvError; +pub use self::error::TrySendError; +pub use self::unbounded::UnboundedReceiver; +pub use self::unbounded::UnboundedSender; +pub use self::unbounded::unbounded; diff --git a/asyncband/src/watch/mod.rs b/asyncband/src/watch/mod.rs index afc0928d..cc8d40e6 100644 --- a/asyncband/src/watch/mod.rs +++ b/asyncband/src/watch/mod.rs @@ -71,11 +71,11 @@ use std::sync::Arc; use std::task::Context; use std::task::Poll; +pub use self::error::RecvError; +pub use self::error::SendError; use crate::internal::mutex::Mutex; use crate::internal::wakerset::WakerSet; use crate::internal::wakerset::WakerToken; -pub use crate::watch::error::RecvError; -pub use crate::watch::error::SendError; /// Creates a watch channel with an initial value. /// From 23e0e3f164c3172b4f6d58a8935039f6d16253b8 Mon Sep 17 00:00:00 2001 From: tison Date: Sun, 11 Oct 2026 13:41:21 +0100 Subject: [PATCH 3/8] style: preserve explicit paths in the mutex wrapper --- asyncband/src/internal/mutex.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/asyncband/src/internal/mutex.rs b/asyncband/src/internal/mutex.rs index 24cd5bf7..93baf8f2 100644 --- a/asyncband/src/internal/mutex.rs +++ b/asyncband/src/internal/mutex.rs @@ -16,11 +16,9 @@ // under the License. use std::fmt; -use std::sync::Mutex as StdMutex; -use std::sync::MutexGuard; use std::sync::PoisonError; -pub struct Mutex(StdMutex); +pub struct Mutex(std::sync::Mutex); impl fmt::Debug for Mutex { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -30,10 +28,10 @@ impl fmt::Debug for Mutex { impl Mutex { pub const fn new(t: T) -> Self { - Self(StdMutex::new(t)) + Self(std::sync::Mutex::new(t)) } - pub fn lock(&self) -> MutexGuard<'_, T> { + pub fn lock(&self) -> std::sync::MutexGuard<'_, T> { self.0.lock().unwrap_or_else(PoisonError::into_inner) } From 9e2b724d0e4d745eceea3823654973b7af12724e Mon Sep 17 00:00:00 2001 From: tison Date: Sun, 11 Oct 2026 13:44:40 +0100 Subject: [PATCH 4/8] style: reuse parent imports in unit tests --- asyncband/src/broadcast/mpmc/common.rs | 4 +--- asyncband/src/internal/semaphore.rs | 2 -- asyncband/src/internal/waker_batch.rs | 3 +-- asyncband/src/internal/wakerset.rs | 2 +- asyncband/src/mpsc/unbounded/buffer.rs | 5 +---- asyncband/src/once/once_map/tests.rs | 4 +--- asyncband/src/oneshot/tests.rs | 12 +++--------- asyncband/src/phaser/tests.rs | 4 +--- asyncband/src/singleflight/tests.rs | 2 +- 9 files changed, 10 insertions(+), 28 deletions(-) diff --git a/asyncband/src/broadcast/mpmc/common.rs b/asyncband/src/broadcast/mpmc/common.rs index 15cb1978..f1a847b0 100644 --- a/asyncband/src/broadcast/mpmc/common.rs +++ b/asyncband/src/broadcast/mpmc/common.rs @@ -531,9 +531,7 @@ pub fn take_msg(msg: Arc, reclaimed: Reclaimed) -> T { #[cfg(test)] mod tests { - use std::sync::Arc; - - use crate::broadcast::mpmc::common::Backlog; + use super::*; /// Drives every cursor-count mutation point — subscribing, publishing, receiving, and dropping /// — and checks the accounting after each step. diff --git a/asyncband/src/internal/semaphore.rs b/asyncband/src/internal/semaphore.rs index 1a539a2b..13b26424 100644 --- a/asyncband/src/internal/semaphore.rs +++ b/asyncband/src/internal/semaphore.rs @@ -385,8 +385,6 @@ fn acquired_or_enqueue( #[cfg(test)] mod tests { use std::sync::Arc; - use std::sync::atomic::AtomicUsize; - use std::sync::atomic::Ordering; use std::task::Wake; use super::*; diff --git a/asyncband/src/internal/waker_batch.rs b/asyncband/src/internal/waker_batch.rs index 25b22391..af27db78 100644 --- a/asyncband/src/internal/waker_batch.rs +++ b/asyncband/src/internal/waker_batch.rs @@ -107,9 +107,8 @@ mod tests { use std::sync::Arc; use std::sync::Mutex; use std::task::Wake; - use std::task::Waker; - use crate::internal::waker_batch::WakerBatch; + use super::*; const STACK_SIZE: usize = WakerBatch::STACK_SIZE; diff --git a/asyncband/src/internal/wakerset.rs b/asyncband/src/internal/wakerset.rs index a909b6c8..58f19aeb 100644 --- a/asyncband/src/internal/wakerset.rs +++ b/asyncband/src/internal/wakerset.rs @@ -111,7 +111,7 @@ impl WakerSet { #[cfg(test)] mod tests { - use crate::internal::wakerset::WakerToken; + use super::*; #[test] fn waker_token_preserves_the_option_niche() { diff --git a/asyncband/src/mpsc/unbounded/buffer.rs b/asyncband/src/mpsc/unbounded/buffer.rs index 0a1a81b4..8cecf3f6 100644 --- a/asyncband/src/mpsc/unbounded/buffer.rs +++ b/asyncband/src/mpsc/unbounded/buffer.rs @@ -98,12 +98,9 @@ pub fn pop_batch(batch: &mut VecDeque) -> T { #[cfg(test)] mod tests { - use std::collections::VecDeque; use std::iter::once; - use crate::mpsc::unbounded::buffer::Buffer; - use crate::mpsc::unbounded::buffer::SEGMENT_BYTES; - use crate::mpsc::unbounded::buffer::pop_batch; + use super::*; fn allocated_bytes(buffer: &Buffer, batch: &VecDeque) -> usize { let slots = batch.capacity() diff --git a/asyncband/src/once/once_map/tests.rs b/asyncband/src/once/once_map/tests.rs index 53a14d73..d89ddacc 100644 --- a/asyncband/src/once/once_map/tests.rs +++ b/asyncband/src/once/once_map/tests.rs @@ -23,11 +23,9 @@ use std::hash::Hasher; use std::panic::AssertUnwindSafe; use std::panic::catch_unwind; use std::pin::pin; -use std::sync::Arc; use std::task::Poll; -use crate::once::once_map::Lookup; -use crate::once::once_map::OnceMap; +use super::*; use crate::test_support::poll_once; // These tests stay next to the implementation because they inspect private state. diff --git a/asyncband/src/oneshot/tests.rs b/asyncband/src/oneshot/tests.rs index 7763986d..d6a9da67 100644 --- a/asyncband/src/oneshot/tests.rs +++ b/asyncband/src/oneshot/tests.rs @@ -26,17 +26,11 @@ use std::future::Future; use std::future::IntoFuture; use std::mem; use std::pin::Pin; -use std::sync::atomic::Ordering; use std::sync::mpsc; use std::task::Context; -use std::task::Poll; use std::time::Duration; -use crate::oneshot; -use crate::oneshot::Channel; -use crate::oneshot::MESSAGE; -use crate::oneshot::RECEIVING; -use crate::oneshot::drop_message_and_deallocate_channel; +use super::*; use crate::oneshot::tests::support::DropProbe; use crate::oneshot::tests::support::WakerProbe; use crate::oneshot::tests::support::spawn_named; @@ -45,7 +39,7 @@ use crate::oneshot::tests::support::spawn_named; #[test] fn poll_returns_while_sender_owns_waker() { - let (sender, receiver) = oneshot::channel(); + let (sender, receiver) = channel(); let channel_ptr = sender.channel_ptr(); mem::forget(sender); let mut receiver = receiver.into_future(); @@ -109,7 +103,7 @@ fn poll_returns_while_sender_owns_waker() { #[test] fn drop_transfers_cleanup_while_sender_owns_waker() { - let (sender, receiver) = oneshot::channel(); + let (sender, receiver) = channel(); let channel_ptr = sender.channel_ptr(); mem::forget(sender); let mut receiver = receiver.into_future(); diff --git a/asyncband/src/phaser/tests.rs b/asyncband/src/phaser/tests.rs index f644cf83..b85b7fcc 100644 --- a/asyncband/src/phaser/tests.rs +++ b/asyncband/src/phaser/tests.rs @@ -15,9 +15,7 @@ // specific language governing permissions and limitations // under the License. -use std::task::Poll; - -use crate::phaser::Phaser; +use super::*; use crate::test_support::poll_once; #[test] diff --git a/asyncband/src/singleflight/tests.rs b/asyncband/src/singleflight/tests.rs index aa0c3f4b..d97ad5b6 100644 --- a/asyncband/src/singleflight/tests.rs +++ b/asyncband/src/singleflight/tests.rs @@ -23,7 +23,7 @@ use std::panic::catch_unwind; use std::pin::pin; use std::task::Poll; -use crate::singleflight::Group; +use super::*; use crate::test_support::poll_once; // These tests stay next to the implementation because they inspect private state. From cbfe3948a985f236611158e39aebfeed66ccf4a8 Mon Sep 17 00:00:00 2001 From: tison Date: Sun, 11 Oct 2026 13:51:04 +0100 Subject: [PATCH 5/8] style: preserve original symbol names in imports --- AGENTS.md | 4 +- asyncband/src/blocking/mod.rs | 4 +- .../ecosystem/broadcast/mpmc/adapters.rs | 31 +++++----- .../ecosystem/broadcast/mpmc/support.rs | 5 +- benchmarks/benches/ecosystem/mpsc/adapters.rs | 26 ++++---- .../benches/ecosystem/mpsc/reservation.rs | 6 +- benchmarks/benches/ecosystem/mpsc/support.rs | 8 +-- benchmarks/benches/ecosystem/waitgroup.rs | 7 +-- .../benches/ecosystem/watch/adapters.rs | 15 ++--- .../benches/primitives/blocking/block_on.rs | 2 +- .../primitives/blocking/wait_timeout.rs | 2 +- benchmarks/src/channels/mpmc.rs | 5 +- tests-integration/tests/composition_test.rs | 2 +- tests-integration/tests/traits_test.rs | 62 +++++++++---------- xtask/src/main.rs | 34 +++++----- 15 files changed, 98 insertions(+), 115 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 767b89a7..40316b2c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -31,9 +31,9 @@ Use the shared [license-audit skill](.agents/skills/license-audit/SKILL.md) for Declare restricted visibility at the module boundary and use `pub` for items in that module's API. -Use imports for referenced symbols. Keep a short module qualifier or use an explicit alias when a bare name would obscure its origin or conflict with another symbol, such as `io::Error`. +Use imports for referenced symbols and preserve their original names. Keep module or crate qualification when it clarifies the source or distinguishes same-named symbols, such as `io::Error`, `pool::bounded`, or `tokio::sync::Barrier`. Avoid `use ... as ...` unless there is a compelling reason; aliases make symbols harder to discover. -Start ordinary intra-crate imports at `crate`; avoid explicit `super::...` imports and qualified paths. Reserve `use super::*` for test modules. +Start ordinary intra-crate imports at `crate`; avoid explicit `super::...` paths. Reserve `use super::*` for test modules. Keep `pub use self::...` when re-exporting a module's own children as its public API. diff --git a/asyncband/src/blocking/mod.rs b/asyncband/src/blocking/mod.rs index 979714ca..95cd671d 100644 --- a/asyncband/src/blocking/mod.rs +++ b/asyncband/src/blocking/mod.rs @@ -26,7 +26,7 @@ //! ``` //! use std::time::Duration; //! -//! use asyncband::blocking::FutureExt as _; +//! use asyncband::blocking::FutureExt; //! //! assert_eq!(async { 42 }.block_on(), 42); //! assert_eq!(async { 42 }.wait_timeout(Duration::ZERO), Some(42)); @@ -67,7 +67,7 @@ use std::time::Duration; /// ``` /// use std::time::Duration; /// -/// use asyncband::blocking::FutureExt as _; +/// use asyncband::blocking::FutureExt; /// /// assert_eq!(async { 42 }.block_on(), 42); /// assert_eq!(async { 42 }.wait_timeout(Duration::ZERO), Some(42)); diff --git a/benchmarks/benches/ecosystem/broadcast/mpmc/adapters.rs b/benchmarks/benches/ecosystem/broadcast/mpmc/adapters.rs index 714fc715..48e72e34 100644 --- a/benchmarks/benches/ecosystem/broadcast/mpmc/adapters.rs +++ b/benchmarks/benches/ecosystem/broadcast/mpmc/adapters.rs @@ -19,10 +19,7 @@ use std::future::Future; use std::task::Context; use asyncband::blocking::FutureExt; -use asyncband::broadcast::mpmc as asyncband_mpmc; use benchmarks::support::poll_ready; -use tokio::sync::broadcast as tokio_broadcast; -use tokio::sync::broadcast::error::TryRecvError as TokioTryRecvError; pub struct Asyncband; pub struct Tokio; @@ -39,11 +36,11 @@ pub trait BroadcastMpmc: Send + Sync + 'static { } impl BroadcastMpmc for Asyncband { - type Receiver = asyncband_mpmc::UnboundedReceiver; - type Sender = asyncband_mpmc::UnboundedSender; + type Receiver = asyncband::broadcast::mpmc::UnboundedReceiver; + type Sender = asyncband::broadcast::mpmc::UnboundedSender; fn channel(_capacity: usize, receiver_count: usize) -> (Self::Sender, Vec) { - let (sender, receiver) = asyncband_mpmc::unbounded(); + let (sender, receiver) = asyncband::broadcast::mpmc::unbounded(); let mut receivers = Vec::with_capacity(receiver_count); receivers.push(receiver); for _ in 1..receiver_count { @@ -59,8 +56,8 @@ impl BroadcastMpmc for Asyncband { fn try_recv(receiver: &mut Self::Receiver) -> Option { match receiver.try_recv() { Ok(value) => Some(value), - Err(asyncband_mpmc::TryRecvError::Empty) => None, - Err(asyncband_mpmc::TryRecvError::Disconnected) => { + Err(asyncband::broadcast::mpmc::TryRecvError::Empty) => None, + Err(asyncband::broadcast::mpmc::TryRecvError::Disconnected) => { panic!("asyncband channel closed during benchmark") } } @@ -72,11 +69,11 @@ impl BroadcastMpmc for Asyncband { } impl BroadcastMpmc for Tokio { - type Receiver = tokio_broadcast::Receiver; - type Sender = tokio_broadcast::Sender; + type Receiver = tokio::sync::broadcast::Receiver; + type Sender = tokio::sync::broadcast::Sender; fn channel(capacity: usize, receiver_count: usize) -> (Self::Sender, Vec) { - let (sender, receiver) = tokio_broadcast::channel(capacity); + let (sender, receiver) = tokio::sync::broadcast::channel(capacity); let mut receivers = Vec::with_capacity(receiver_count); receivers.push(receiver); for _ in 1..receiver_count { @@ -92,7 +89,7 @@ impl BroadcastMpmc for Tokio { fn try_recv(receiver: &mut Self::Receiver) -> Option { match receiver.try_recv() { Ok(value) => Some(value), - Err(TokioTryRecvError::Empty) => None, + Err(tokio::sync::broadcast::error::TryRecvError::Empty) => None, Err(error) => panic!("unexpected Tokio receive error: {error}"), } } @@ -164,11 +161,11 @@ pub trait BoundedBroadcastMpmc: Send + Sync + 'static { } impl BoundedBroadcastMpmc for Asyncband { - type Receiver = asyncband_mpmc::BoundedReceiver; - type Sender = asyncband_mpmc::BoundedSender; + type Receiver = asyncband::broadcast::mpmc::BoundedReceiver; + type Sender = asyncband::broadcast::mpmc::BoundedSender; fn channel(capacity: usize, receiver_count: usize) -> (Self::Sender, Vec) { - let (sender, receiver) = asyncband_mpmc::bounded(capacity); + let (sender, receiver) = asyncband::broadcast::mpmc::bounded(capacity); let mut receivers = Vec::with_capacity(receiver_count); receivers.push(receiver); for _ in 1..receiver_count { @@ -192,8 +189,8 @@ impl BoundedBroadcastMpmc for Asyncband { fn try_recv(receiver: &mut Self::Receiver) -> Option { match receiver.try_recv() { Ok(value) => Some(value), - Err(asyncband_mpmc::TryRecvError::Empty) => None, - Err(asyncband_mpmc::TryRecvError::Disconnected) => { + Err(asyncband::broadcast::mpmc::TryRecvError::Empty) => None, + Err(asyncband::broadcast::mpmc::TryRecvError::Disconnected) => { panic!("asyncband channel closed during benchmark") } } diff --git a/benchmarks/benches/ecosystem/broadcast/mpmc/support.rs b/benchmarks/benches/ecosystem/broadcast/mpmc/support.rs index 19201883..17f1133e 100644 --- a/benchmarks/benches/ecosystem/broadcast/mpmc/support.rs +++ b/benchmarks/benches/ecosystem/broadcast/mpmc/support.rs @@ -24,7 +24,6 @@ use std::thread::JoinHandle; use divan::black_box; use tokio::runtime::Runtime; -use tokio::sync::Barrier as TokioBarrier; use tokio::task::JoinSet; use crate::broadcast::mpmc::adapters::BoundedBroadcastMpmc; @@ -253,7 +252,7 @@ impl BoundedConcurrent { } pub struct BoundedTasks { - start: Arc, + start: Arc, tasks: JoinSet<()>, } @@ -266,7 +265,7 @@ impl BoundedTasks { } = shape; assert_eq!(BATCH_MESSAGES % producers, 0); let (sender, receivers) = C::channel(capacity, receivers); - let start = Arc::new(TokioBarrier::new(producers + receivers.len() + 1)); + let start = Arc::new(tokio::sync::Barrier::new(producers + receivers.len() + 1)); let mut tasks = JoinSet::new(); for mut receiver in receivers { diff --git a/benchmarks/benches/ecosystem/mpsc/adapters.rs b/benchmarks/benches/ecosystem/mpsc/adapters.rs index df5cfb17..cf28713b 100644 --- a/benchmarks/benches/ecosystem/mpsc/adapters.rs +++ b/benchmarks/benches/ecosystem/mpsc/adapters.rs @@ -20,9 +20,7 @@ use std::future::Future; use std::task::Context; use asyncband::blocking::FutureExt; -use asyncband::mpsc as asyncband_mpsc; use benchmarks::support::poll_ready; -use tokio::sync::mpsc as tokio_mpsc; pub struct Asyncband; pub struct Tokio; @@ -57,11 +55,11 @@ pub trait UnboundedMpsc: Send + Sync + 'static { } impl BoundedMpsc for Asyncband { - type Receiver = asyncband_mpsc::BoundedReceiver; - type Sender = asyncband_mpsc::BoundedSender; + type Receiver = asyncband::mpsc::BoundedReceiver; + type Sender = asyncband::mpsc::BoundedSender; fn channel(capacity: usize) -> (Self::Sender, Self::Receiver) { - asyncband_mpsc::bounded(capacity) + asyncband::mpsc::bounded(capacity) } fn try_send(sender: &Self::Sender, value: T) { @@ -98,11 +96,11 @@ impl BoundedMpsc for Asyncband { } impl BoundedMpsc for Tokio { - type Receiver = tokio_mpsc::Receiver; - type Sender = tokio_mpsc::Sender; + type Receiver = tokio::sync::mpsc::Receiver; + type Sender = tokio::sync::mpsc::Sender; fn channel(capacity: usize) -> (Self::Sender, Self::Receiver) { - tokio_mpsc::channel(capacity) + tokio::sync::mpsc::channel(capacity) } fn try_send(sender: &Self::Sender, value: T) { @@ -221,11 +219,11 @@ impl BoundedMpsc for Flume { } impl UnboundedMpsc for Asyncband { - type Receiver = asyncband_mpsc::UnboundedReceiver; - type Sender = asyncband_mpsc::UnboundedSender; + type Receiver = asyncband::mpsc::UnboundedReceiver; + type Sender = asyncband::mpsc::UnboundedSender; fn channel() -> (Self::Sender, Self::Receiver) { - asyncband_mpsc::unbounded() + asyncband::mpsc::unbounded() } fn send(sender: &Self::Sender, value: T) { @@ -250,11 +248,11 @@ impl UnboundedMpsc for Asyncband { } impl UnboundedMpsc for Tokio { - type Receiver = tokio_mpsc::UnboundedReceiver; - type Sender = tokio_mpsc::UnboundedSender; + type Receiver = tokio::sync::mpsc::UnboundedReceiver; + type Sender = tokio::sync::mpsc::UnboundedSender; fn channel() -> (Self::Sender, Self::Receiver) { - tokio_mpsc::unbounded_channel() + tokio::sync::mpsc::unbounded_channel() } fn send(sender: &Self::Sender, value: T) { diff --git a/benchmarks/benches/ecosystem/mpsc/reservation.rs b/benchmarks/benches/ecosystem/mpsc/reservation.rs index 8eda086e..fbbd8637 100644 --- a/benchmarks/benches/ecosystem/mpsc/reservation.rs +++ b/benchmarks/benches/ecosystem/mpsc/reservation.rs @@ -19,13 +19,11 @@ use std::future::Future; use std::marker::PhantomData; use asyncband::blocking::FutureExt; -use asyncband::mpsc as asyncband_mpsc; use benchmarks::support::bench_context; use benchmarks::support::poll_ready; use divan::Bencher; use divan::black_box; use divan::counter::ItemsCount; -use tokio::sync::mpsc as tokio_mpsc; use crate::mpsc::adapters::Asyncband; use crate::mpsc::adapters::BoundedMpsc; @@ -44,7 +42,7 @@ trait Reservable: BoundedMpsc { } impl Reservable for Asyncband { - type Permit<'a> = asyncband_mpsc::Permit<'a, usize>; + type Permit<'a> = asyncband::mpsc::Permit<'a, usize>; fn try_reserve(sender: &Self::Sender) -> Self::Permit<'_> { sender.try_reserve().unwrap() } @@ -57,7 +55,7 @@ impl Reservable for Asyncband { } impl Reservable for Tokio { - type Permit<'a> = tokio_mpsc::Permit<'a, usize>; + type Permit<'a> = tokio::sync::mpsc::Permit<'a, usize>; fn try_reserve(sender: &Self::Sender) -> Self::Permit<'_> { sender.try_reserve().unwrap() } diff --git a/benchmarks/benches/ecosystem/mpsc/support.rs b/benchmarks/benches/ecosystem/mpsc/support.rs index a098946b..14dde891 100644 --- a/benchmarks/benches/ecosystem/mpsc/support.rs +++ b/benchmarks/benches/ecosystem/mpsc/support.rs @@ -30,10 +30,8 @@ pub use benchmarks::channels::BOUNDED_CAPACITY; use divan::black_box; use tokio::runtime::Builder; use tokio::runtime::Runtime; -use tokio::sync::Barrier as TokioBarrier; use tokio::sync::Notify; use tokio::sync::mpsc; -use tokio::task::JoinHandle as TokioJoinHandle; use crate::mpsc::adapters::BoundedMpsc; use crate::mpsc::adapters::UnboundedMpsc; @@ -264,9 +262,9 @@ enum Receiver { pub struct RepeatedTasks { runtime: Runtime, receiver: Receiver, - start: Arc, + start: Arc, stop: Arc, - workers: Vec>, + workers: Vec>, } impl RepeatedTasks { @@ -293,7 +291,7 @@ impl RepeatedTasks { .unwrap() }; let (sender, mut receiver) = C::channel(); - let start = Arc::new(TokioBarrier::new(producer_count + 1)); + let start = Arc::new(tokio::sync::Barrier::new(producer_count + 1)); let stop = Arc::new(AtomicBool::new(false)); let messages_per_producer = BATCH_MESSAGES / producer_count; let mut workers: Vec<_> = (0..producer_count) diff --git a/benchmarks/benches/ecosystem/waitgroup.rs b/benchmarks/benches/ecosystem/waitgroup.rs index 9ebd8f90..f9886452 100644 --- a/benchmarks/benches/ecosystem/waitgroup.rs +++ b/benchmarks/benches/ecosystem/waitgroup.rs @@ -19,7 +19,6 @@ use std::future::Future; use std::future::IntoFuture; use std::pin::pin; -use asyncband::waitgroup as asyncband_waitgroup; use benchmarks::support::bench_context; use benchmarks::support::poll_pending; use benchmarks::support::poll_pinned_ready; @@ -42,9 +41,9 @@ trait WaitGroup { } impl WaitGroup for Asyncband { - type Group = asyncband_waitgroup::WaitGroup; - type Worker = asyncband_waitgroup::WaitGroup; - type Wait = asyncband_waitgroup::Wait; + type Group = asyncband::waitgroup::WaitGroup; + type Worker = asyncband::waitgroup::WaitGroup; + type Wait = asyncband::waitgroup::Wait; fn new() -> Self::Group { Self::Group::new() diff --git a/benchmarks/benches/ecosystem/watch/adapters.rs b/benchmarks/benches/ecosystem/watch/adapters.rs index 52cc1b03..f5a9b6e7 100644 --- a/benchmarks/benches/ecosystem/watch/adapters.rs +++ b/benchmarks/benches/ecosystem/watch/adapters.rs @@ -17,9 +17,6 @@ use std::future::Future; -use asyncband::watch as asyncband_watch; -use tokio::sync::watch as tokio_watch; - pub struct Asyncband; pub struct Tokio; @@ -35,11 +32,11 @@ pub trait Watch: Send + Sync + 'static { } impl Watch for Asyncband { - type Sender = asyncband_watch::Sender; - type Receiver = asyncband_watch::Receiver; + type Sender = asyncband::watch::Sender; + type Receiver = asyncband::watch::Receiver; fn channel(receiver_count: usize) -> (Self::Sender, Vec) { - let (sender, first) = asyncband_watch::channel(0); + let (sender, first) = asyncband::watch::channel(0); let mut receivers = Vec::with_capacity(receiver_count); receivers.push(first); receivers.extend((1..receiver_count).map(|_| sender.subscribe())); @@ -64,11 +61,11 @@ impl Watch for Asyncband { } impl Watch for Tokio { - type Sender = tokio_watch::Sender; - type Receiver = tokio_watch::Receiver; + type Sender = tokio::sync::watch::Sender; + type Receiver = tokio::sync::watch::Receiver; fn channel(receiver_count: usize) -> (Self::Sender, Vec) { - let (sender, first) = tokio_watch::channel(0); + let (sender, first) = tokio::sync::watch::channel(0); let mut receivers = Vec::with_capacity(receiver_count); receivers.push(first); receivers.extend((1..receiver_count).map(|_| sender.subscribe())); diff --git a/benchmarks/benches/primitives/blocking/block_on.rs b/benchmarks/benches/primitives/blocking/block_on.rs index d7524bba..8faa57af 100644 --- a/benchmarks/benches/primitives/blocking/block_on.rs +++ b/benchmarks/benches/primitives/blocking/block_on.rs @@ -21,7 +21,7 @@ use std::task::Poll; use std::task::Waker; use std::thread; -use asyncband::blocking::FutureExt as _; +use asyncband::blocking::FutureExt; use divan::Bencher; use divan::black_box; diff --git a/benchmarks/benches/primitives/blocking/wait_timeout.rs b/benchmarks/benches/primitives/blocking/wait_timeout.rs index 1cd1efd7..c0e62725 100644 --- a/benchmarks/benches/primitives/blocking/wait_timeout.rs +++ b/benchmarks/benches/primitives/blocking/wait_timeout.rs @@ -17,7 +17,7 @@ use std::time::Duration; -use asyncband::blocking::FutureExt as _; +use asyncband::blocking::FutureExt; use divan::Bencher; use divan::black_box; diff --git a/benchmarks/src/channels/mpmc.rs b/benchmarks/src/channels/mpmc.rs index a32606b4..8348058d 100644 --- a/benchmarks/src/channels/mpmc.rs +++ b/benchmarks/src/channels/mpmc.rs @@ -23,7 +23,6 @@ use std::thread::JoinHandle; use divan::black_box; use tokio::runtime::Runtime; -use tokio::sync::Barrier as TokioBarrier; use tokio::task::JoinSet; use crate::channels::BATCH_MESSAGES; @@ -77,7 +76,7 @@ pub const TOPOLOGIES: &[Topology] = &[ // The caller only coordinates the batch. Spawned tasks send and receive all measured messages, // including on the current-thread runtime; `Runtime::block_on` itself receives no data. pub struct TaskBatch { - start: Arc, + start: Arc, workers: JoinSet<(usize, usize)>, } @@ -88,7 +87,7 @@ impl TaskBatch { { assert_eq!(BATCH_MESSAGES % topology.producers, 0); let (sender, receiver) = C::channel(); - let start = Arc::new(TokioBarrier::new( + let start = Arc::new(tokio::sync::Barrier::new( topology.producers + topology.consumers + 1, )); let messages_per_producer = BATCH_MESSAGES / topology.producers; diff --git a/tests-integration/tests/composition_test.rs b/tests-integration/tests/composition_test.rs index 64ac539b..f6b14dda 100644 --- a/tests-integration/tests/composition_test.rs +++ b/tests-integration/tests/composition_test.rs @@ -20,7 +20,7 @@ use std::thread; use std::time::Duration; use asyncband::barrier::Barrier; -use asyncband::blocking::FutureExt as _; +use asyncband::blocking::FutureExt; use asyncband::mutex::Mutex; use asyncband::oneshot; diff --git a/tests-integration/tests/traits_test.rs b/tests-integration/tests/traits_test.rs index f5dc0cdb..2d7c88c6 100644 --- a/tests-integration/tests/traits_test.rs +++ b/tests-integration/tests/traits_test.rs @@ -22,10 +22,9 @@ use std::future::Ready; use std::marker::PhantomPinned; use std::panic::RefUnwindSafe; use std::panic::UnwindSafe; -use std::sync::MutexGuard as StdMutexGuard; use asyncband::barrier::Barrier; -use asyncband::broadcast::mpmc as broadcast_mpmc; +use asyncband::broadcast; use asyncband::completion; use asyncband::condvar::Condvar; use asyncband::event::AutoResetEvent; @@ -44,10 +43,9 @@ use asyncband::phaser::Closed; use asyncband::phaser::Phaser; use asyncband::phaser::PhaserParticipant; use asyncband::phaser::PhaserParticipants; +use asyncband::pool; use asyncband::pool::ManageObject; use asyncband::pool::ObjectStatus; -use asyncband::pool::bounded as bounded_pool; -use asyncband::pool::unbounded as unbounded_pool; use asyncband::rwlock::MappedRwLockReadGuard; use asyncband::rwlock::MappedRwLockWriteGuard; use asyncband::rwlock::OwnedMappedRwLockWriteGuard; @@ -112,24 +110,24 @@ fn public_types_are_send_and_sync() { assert_send_and_sync::>(); assert_send_and_sync::>(); assert_send_and_sync::>(); - assert_send_and_sync::>(); - assert_send_and_sync::>(); - assert_send_and_sync::>(); - assert_send_and_sync::>(); - assert_send_and_sync::(); - assert_send_and_sync::(); - assert_send_and_sync::>(); + assert_send_and_sync::>(); + assert_send_and_sync::>(); + assert_send_and_sync::>(); + assert_send_and_sync::>(); + assert_send_and_sync::(); + assert_send_and_sync::(); + assert_send_and_sync::>(); assert_send_and_sync::>(); assert_send_and_sync::>(); assert_send_and_sync::(); assert_send_and_sync::(); assert_send_and_sync::(); assert_send_and_sync::(); - assert_send_and_sync::>(); - assert_send_and_sync::>(); - assert_send_and_sync::>(); - assert_send_and_sync::>(); - assert_send_and_sync::>>(); + assert_send_and_sync::>(); + assert_send_and_sync::>(); + assert_send_and_sync::>(); + assert_send_and_sync::>(); + assert_send_and_sync::>>(); assert_send_and_sync::>(); assert_send_and_sync::>(); assert_send_and_sync::>(); @@ -155,13 +153,13 @@ fn movable_public_types_are_send() { fn assert_send() {} fn assert_send_value(_: T) {} - assert_send::>>(); - assert_send::>>(); + assert_send::>>(); + assert_send::>>(); assert_send::>>(); assert_send::>>(); assert_send::>(); assert_send::>(); - assert_send::>>(); + assert_send::>>(); let (_tx, mut rx) = watch::channel(0); assert_send_value(rx.changed()); @@ -207,13 +205,13 @@ fn public_types_are_unpin() { assert_unpin::>(); assert_unpin::>(); assert_unpin::>(); - assert_unpin::>(); - assert_unpin::>(); - assert_unpin::>(); - assert_unpin::>(); - assert_unpin::(); - assert_unpin::(); - assert_unpin::>(); + assert_unpin::>(); + assert_unpin::>(); + assert_unpin::>(); + assert_unpin::>(); + assert_unpin::(); + assert_unpin::(); + assert_unpin::>(); assert_unpin::>(); assert_unpin::>(); assert_unpin::>(); @@ -222,10 +220,10 @@ fn public_types_are_unpin() { assert_unpin::(); assert_unpin::(); assert_unpin::(); - assert_unpin::>(); - assert_unpin::>(); - assert_unpin::>(); - assert_unpin::>(); + assert_unpin::>(); + assert_unpin::>(); + assert_unpin::>(); + assert_unpin::>(); assert_unpin::>(); assert_unpin::>(); assert_unpin::>(); @@ -281,6 +279,6 @@ fn unbounded_manual_manager_traits_do_not_depend_on_the_object() { fn assert_copy() {} fn assert_debug() {} - assert_copy::>(); - assert_debug::>(); + assert_copy::>(); + assert_debug::>(); } diff --git a/xtask/src/main.rs b/xtask/src/main.rs index a8526486..b48b97f1 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -16,7 +16,7 @@ // under the License. use std::path::Path; -use std::process::Command as StdCommand; +use std::process; use std::process::ExitStatus; use std::time::Duration; @@ -285,10 +285,10 @@ impl SemverReleaseType { } } -fn find_command(cmd: &str) -> StdCommand { +fn find_command(cmd: &str) -> process::Command { match which::which(cmd) { Ok(exe) => { - let mut cmd = StdCommand::new(exe); + let mut cmd = process::Command::new(exe); cmd.current_dir(env!("CARGO_WORKSPACE_DIR")); cmd } @@ -306,12 +306,12 @@ fn ensure_installed(bin: &str, crate_name: &str) { } } -fn run_command(cmd: StdCommand) { +fn run_command(cmd: process::Command) { let status = command_status(cmd); assert!(status.success(), "command failed: {status}"); } -fn command_status(mut cmd: StdCommand) -> ExitStatus { +fn command_status(mut cmd: process::Command) -> ExitStatus { println!("{cmd:?}"); cmd.status().expect("failed to execute process") } @@ -380,7 +380,7 @@ fn classify_release_type(baseline: &Version, release: &Version) -> SemverRelease } } -fn make_bench_cmd(no_run: bool, bench: Option<&str>, args: &[String]) -> StdCommand { +fn make_bench_cmd(no_run: bool, bench: Option<&str>, args: &[String]) -> process::Command { let mut cmd = find_command("cargo"); cmd.args([ "bench", @@ -398,7 +398,7 @@ fn make_bench_cmd(no_run: bool, bench: Option<&str>, args: &[String]) -> StdComm cmd } -fn make_build_cmd(locked: bool) -> StdCommand { +fn make_build_cmd(locked: bool) -> process::Command { let mut cmd = find_command("cargo"); cmd.args([ "build", @@ -415,7 +415,7 @@ fn make_build_cmd(locked: bool) -> StdCommand { cmd } -fn make_test_cmd(no_capture: bool, features: &[String]) -> StdCommand { +fn make_test_cmd(no_capture: bool, features: &[String]) -> process::Command { let mut cmd = find_command("cargo"); cmd.args(["test", "--workspace", "--no-default-features"]); for feature in features { @@ -427,7 +427,7 @@ fn make_test_cmd(no_capture: bool, features: &[String]) -> StdCommand { cmd } -fn make_check_cmd(features: &[String]) -> StdCommand { +fn make_check_cmd(features: &[String]) -> process::Command { let mut cmd = find_command("cargo"); cmd.env("RUSTFLAGS", "-Dwarnings"); cmd.args([ @@ -444,14 +444,14 @@ fn make_check_cmd(features: &[String]) -> StdCommand { cmd } -fn make_miri_cmd(package: &str, target: &[&str]) -> StdCommand { +fn make_miri_cmd(package: &str, target: &[&str]) -> process::Command { let mut cmd = find_command("cargo"); cmd.args(["+nightly", "miri", "test", "--package", package]); cmd.args(target); cmd } -fn make_format_cmd(fix: bool) -> StdCommand { +fn make_format_cmd(fix: bool) -> process::Command { let mut cmd = find_command("cargo"); cmd.args(["+nightly", "fmt", "--all"]); if !fix { @@ -460,7 +460,7 @@ fn make_format_cmd(fix: bool) -> StdCommand { cmd } -fn make_clippy_cmd(fix: bool) -> StdCommand { +fn make_clippy_cmd(fix: bool) -> process::Command { let mut cmd = find_command("cargo"); cmd.args([ "+nightly", @@ -478,7 +478,7 @@ fn make_clippy_cmd(fix: bool) -> StdCommand { cmd } -fn make_doc_cmd() -> StdCommand { +fn make_doc_cmd() -> process::Command { let mut cmd = find_command("cargo"); cmd.env("RUSTDOCFLAGS", "-D warnings --cfg docsrs"); cmd.args([ @@ -494,7 +494,7 @@ fn make_doc_cmd() -> StdCommand { fn make_semver_check_cmd( baseline_version: &Version, release_type: SemverReleaseType, -) -> StdCommand { +) -> process::Command { ensure_installed("cargo-semver-checks", "cargo-semver-checks"); let mut cmd = find_command("cargo"); cmd.args([ @@ -511,7 +511,7 @@ fn make_semver_check_cmd( cmd } -fn make_hawkeye_cmd(fix: bool) -> StdCommand { +fn make_hawkeye_cmd(fix: bool) -> process::Command { ensure_installed("hawkeye", "hawkeye"); let mut cmd = find_command("hawkeye"); if fix { @@ -522,12 +522,12 @@ fn make_hawkeye_cmd(fix: bool) -> StdCommand { cmd } -fn make_typos_cmd() -> StdCommand { +fn make_typos_cmd() -> process::Command { ensure_installed("typos", "typos-cli"); find_command("typos") } -fn make_taplo_cmd(fix: bool) -> StdCommand { +fn make_taplo_cmd(fix: bool) -> process::Command { ensure_installed("taplo", "taplo-cli"); let mut cmd = find_command("taplo"); if fix { From afb3c54c1cae2befd66028448f634f27911ee0ee Mon Sep 17 00:00:00 2001 From: tison Date: Sun, 11 Oct 2026 13:56:24 +0100 Subject: [PATCH 6/8] style: keep meaningful function qualifiers --- AGENTS.md | 2 +- asyncband/src/mpsc/unbounded/buffer.rs | 4 ++-- asyncband/src/pool/bounded.rs | 3 +-- asyncband/src/pool/mod.rs | 3 +-- asyncband/src/pool/unbounded.rs | 3 +-- asyncband/src/singleflight/mod.rs | 10 ++++------ benchmarks/benches/ecosystem/mpsc/unbounded.rs | 4 ++-- examples/src/coalesced_worker.rs | 3 +-- examples/src/graceful_shutdown.rs | 8 +++----- examples/src/lazy_cell_boxed_vs_inline.rs | 3 +-- examples/src/notify_vs_event.rs | 5 ++--- examples/src/phaser_completion.rs | 3 +-- examples/src/phaser_rounds.rs | 3 +-- examples/src/shared_completion.rs | 3 +-- tests-integration/tests/condvar_test.rs | 3 +-- tests-integration/tests/lazy_cell_test.rs | 5 ++--- tests-integration/tests/mpmc_test/concurrency.rs | 3 +-- tests-integration/tests/mpsc_test/concurrency.rs | 13 ++++++------- tests-integration/tests/mutex_test.rs | 3 +-- tests-integration/tests/phaser_test.rs | 5 ++--- tests-integration/tests/rwlock_test.rs | 7 +++---- tests-integration/tests/spmc_test/concurrency.rs | 3 +-- 22 files changed, 39 insertions(+), 60 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 40316b2c..cefe6005 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -31,7 +31,7 @@ Use the shared [license-audit skill](.agents/skills/license-audit/SKILL.md) for Declare restricted visibility at the module boundary and use `pub` for items in that module's API. -Use imports for referenced symbols and preserve their original names. Keep module or crate qualification when it clarifies the source or distinguishes same-named symbols, such as `io::Error`, `pool::bounded`, or `tokio::sync::Barrier`. Avoid `use ... as ...` unless there is a compelling reason; aliases make symbols harder to discover. +Use imports for referenced symbols and preserve their original names. Keep enough module or crate qualification to explain the operation, identify its source or execution context, and distinguish same-named symbols, such as `io::Error`, `pool::bounded`, `iter::once`, or `tokio::time::sleep`. Meaningful qualification is useful even without a name conflict. Avoid `use ... as ...` unless there is a compelling reason; aliases make symbols harder to discover. Start ordinary intra-crate imports at `crate`; avoid explicit `super::...` paths. Reserve `use super::*` for test modules. diff --git a/asyncband/src/mpsc/unbounded/buffer.rs b/asyncband/src/mpsc/unbounded/buffer.rs index 8cecf3f6..b4c8be21 100644 --- a/asyncband/src/mpsc/unbounded/buffer.rs +++ b/asyncband/src/mpsc/unbounded/buffer.rs @@ -98,7 +98,7 @@ pub fn pop_batch(batch: &mut VecDeque) -> T { #[cfg(test)] mod tests { - use std::iter::once; + use std::iter; use super::*; @@ -147,7 +147,7 @@ mod tests { for _ in 0..2 { for value in 0..messages { buffer.push([value as u8; SIZE]); - for segment in once(&buffer.writable).chain(&buffer.sealed) { + for segment in iter::once(&buffer.writable).chain(&buffer.sealed) { assert!(segment.capacity() * SIZE <= SEGMENT_BYTES); } } diff --git a/asyncband/src/pool/bounded.rs b/asyncband/src/pool/bounded.rs index 947435a5..1a5f9de6 100644 --- a/asyncband/src/pool/bounded.rs +++ b/asyncband/src/pool/bounded.rs @@ -337,7 +337,6 @@ impl Pool { /// # use asyncband::pool::ObjectStatus; /// # use asyncband::pool::bounded::Pool; /// # use asyncband::pool::bounded::PoolConfig; - /// use tokio::time::sleep; /// let interval = Duration::from_secs(30); /// let max_age = Duration::from_secs(60); /// @@ -362,7 +361,7 @@ impl Pool { /// let weak_pool = Arc::downgrade(&pool); /// tokio::spawn(async move { /// loop { - /// sleep(interval).await; + /// tokio::time::sleep(interval).await; /// if let Some(pool) = weak_pool.upgrade() { /// pool.retain(|_, status| status.last_used().elapsed() < max_age); /// } else { diff --git a/asyncband/src/pool/mod.rs b/asyncband/src/pool/mod.rs index b9c05a00..c4068fa2 100644 --- a/asyncband/src/pool/mod.rs +++ b/asyncband/src/pool/mod.rs @@ -124,7 +124,6 @@ //! use asyncband::pool::bounded::Object; //! use asyncband::pool::bounded::Pool; //! # use asyncband::pool::bounded::PoolConfig; -//! use tokio::time::timeout; //! //! # struct Connection; //! # #[derive(Debug)] @@ -161,7 +160,7 @@ //! const ACQUIRE_TIMEOUT: Duration = Duration::from_secs(60); //! //! // Callers can use the timer implementation of their runtime. -//! match timeout(ACQUIRE_TIMEOUT, self.pool.get()).await { +//! match tokio::time::timeout(ACQUIRE_TIMEOUT, self.pool.get()).await { //! Ok(result) => result.map_err(AcquireError::Create), //! Err(_) => Err(AcquireError::Timeout), //! } diff --git a/asyncband/src/pool/unbounded.rs b/asyncband/src/pool/unbounded.rs index a9a66757..e4478433 100644 --- a/asyncband/src/pool/unbounded.rs +++ b/asyncband/src/pool/unbounded.rs @@ -426,7 +426,6 @@ impl> Pool { /// # use std::time::Duration; /// # use asyncband::pool::unbounded::Pool; /// # use asyncband::pool::unbounded::PoolConfig; - /// use tokio::time::sleep; /// let interval = Duration::from_secs(30); /// let max_age = Duration::from_secs(60); /// @@ -434,7 +433,7 @@ impl> Pool { /// let weak_pool = Arc::downgrade(&pool); /// tokio::spawn(async move { /// loop { - /// sleep(interval).await; + /// tokio::time::sleep(interval).await; /// if let Some(pool) = weak_pool.upgrade() { /// pool.retain(|_, status| status.last_used().elapsed() < max_age); /// } else { diff --git a/asyncband/src/singleflight/mod.rs b/asyncband/src/singleflight/mod.rs index f3470a4a..104193ac 100644 --- a/asyncband/src/singleflight/mod.rs +++ b/asyncband/src/singleflight/mod.rs @@ -253,7 +253,6 @@ where /// use std::time::Duration; /// /// use asyncband::singleflight::Group; - /// use tokio::time::sleep; /// /// # #[tokio::main] /// # async fn main() { @@ -264,7 +263,7 @@ where /// let fut1 = group.work("key", || async move { /// c1.fetch_add(1, Ordering::SeqCst); /// // simulate heavy work to avoid immediate completion - /// sleep(Duration::from_millis(100)).await; + /// tokio::time::sleep(Duration::from_millis(100)).await; /// "result" /// }); /// @@ -272,7 +271,7 @@ where /// let fut2 = group.work("key", || async move { /// c2.fetch_add(1, Ordering::SeqCst); /// // simulate heavy work to avoid immediate completion - /// sleep(Duration::from_millis(100)).await; + /// tokio::time::sleep(Duration::from_millis(100)).await; /// "result" /// }); /// @@ -329,7 +328,6 @@ where /// use std::time::Duration; /// /// use asyncband::singleflight::Group; - /// use tokio::time::sleep; /// /// # #[tokio::main] /// # async fn main() { @@ -337,13 +335,13 @@ where /// /// let fut1 = group.try_work("key", || async move { /// // simulate heavy work to avoid immediate completion - /// sleep(Duration::from_millis(100)).await; + /// tokio::time::sleep(Duration::from_millis(100)).await; /// Err::<_, &'static str>("fut1") /// }); /// /// let fut2 = group.try_work("key", || async move { /// // simulate heavy work to avoid immediate completion - /// sleep(Duration::from_millis(200)).await; + /// tokio::time::sleep(Duration::from_millis(200)).await; /// Ok::<_, &'static str>("fut2") /// }); /// diff --git a/benchmarks/benches/ecosystem/mpsc/unbounded.rs b/benchmarks/benches/ecosystem/mpsc/unbounded.rs index a9fcd700..0e1b6784 100644 --- a/benchmarks/benches/ecosystem/mpsc/unbounded.rs +++ b/benchmarks/benches/ecosystem/mpsc/unbounded.rs @@ -28,7 +28,6 @@ use divan::black_box; use divan::counter::ItemsCount; use tokio::runtime::Builder; use tokio::sync::Notify; -use tokio::task::unconstrained; use crate::mpsc::adapters::AsyncChannel; use crate::mpsc::adapters::Asyncband; @@ -231,7 +230,8 @@ fn scheduled_bursts_inline>( // Exclude Tokio's cooperative-budget Pending from the initial empty probe. // Retain the same `recv_async` future so its channel registration drives the // wake. - let mut receive = pin!(unconstrained(C::recv_async(&mut receiver))); + let mut receive = + pin!(tokio::task::unconstrained(C::recv_async(&mut receiver))); let mut released = false; poll_fn(|cx| { let result = receive.as_mut().poll(cx); diff --git a/examples/src/coalesced_worker.rs b/examples/src/coalesced_worker.rs index 21fdff44..52a1cd3c 100644 --- a/examples/src/coalesced_worker.rs +++ b/examples/src/coalesced_worker.rs @@ -23,7 +23,6 @@ use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; use asyncband::event::AutoResetEvent; -use tokio::task::yield_now; #[derive(Default)] struct Rebuilder { @@ -71,7 +70,7 @@ async fn main() { rebuilder.request(1); rebuilder.request(2); rebuilder.request(3); - yield_now().await; + tokio::task::yield_now().await; // After rebuilding revision 3, the worker waits for another update. rebuilder.request(4); diff --git a/examples/src/graceful_shutdown.rs b/examples/src/graceful_shutdown.rs index ee800e66..36ec43ea 100644 --- a/examples/src/graceful_shutdown.rs +++ b/examples/src/graceful_shutdown.rs @@ -23,9 +23,7 @@ use std::time::Duration; use asyncband::shutdown; use asyncband::shutdown::ShutdownGuard; -use tokio::signal::ctrl_c; use tokio::sync::oneshot; -use tokio::time::sleep; #[tokio::main(flavor = "current_thread")] async fn main() -> Result<(), Box> { @@ -35,7 +33,7 @@ async fn main() -> Result<(), Box> { // A real service can give this sender to an administrative endpoint. let (_admin_shutdown_tx, admin_shutdown_rx) = oneshot::channel::<()>(); let reason = tokio::select! { - result = ctrl_c() => { + result = tokio::signal::ctrl_c() => { result?; "Ctrl+C" } @@ -51,7 +49,7 @@ async fn main() -> Result<(), Box> { shutdown.request_shutdown(); let completed = tokio::select! { _ = shutdown => true, - _ = sleep(Duration::from_secs(30)) => false, + _ = tokio::time::sleep(Duration::from_secs(30)) => false, }; if !completed { @@ -72,7 +70,7 @@ async fn run_worker(guard: ShutdownGuard) { loop { tokio::select! { _ = guard.shutdown_requested() => break, - _ = sleep(Duration::from_secs(1)) => { + _ = tokio::time::sleep(Duration::from_secs(1)) => { println!("worker completed another unit of work"); } } diff --git a/examples/src/lazy_cell_boxed_vs_inline.rs b/examples/src/lazy_cell_boxed_vs_inline.rs index fb3e2ade..2b1ca67b 100644 --- a/examples/src/lazy_cell_boxed_vs_inline.rs +++ b/examples/src/lazy_cell_boxed_vs_inline.rs @@ -22,7 +22,6 @@ use std::pin::pin; use std::sync::Arc; use asyncband::once::LazyCell; -use tokio::task::yield_now; #[tokio::main(flavor = "current_thread")] async fn main() { @@ -48,7 +47,7 @@ async fn main() { // Arc::pin allocates the cell once and keeps its inline future at a stable address. Cloning the // pinned Arc lets multiple tasks resume the same future without a separate future allocation. let shared = Arc::pin(LazyCell::new(async || { - yield_now().await; + tokio::task::yield_now().await; "shared".to_owned() })); diff --git a/examples/src/notify_vs_event.rs b/examples/src/notify_vs_event.rs index 1b1fa1df..5c6e7598 100644 --- a/examples/src/notify_vs_event.rs +++ b/examples/src/notify_vs_event.rs @@ -30,7 +30,6 @@ use std::sync::atomic::Ordering; use asyncband::event::AutoResetEvent; use asyncband::watch; use tokio::sync::Notify; -use tokio::task::yield_now; #[tokio::main(flavor = "current_thread")] async fn main() { @@ -113,7 +112,7 @@ async fn index_readers_with_notify() { // The indexer finishes applying this revision before publishing it. indexed.store(revision, Ordering::Release); changed.notify_waiters(); - yield_now().await; + tokio::task::yield_now().await; } }; @@ -159,7 +158,7 @@ async fn index_readers_with_watch() { for revision in 1..=2 { // Publishing also works when there are temporarily no requests listening. indexed.send_replace(revision); - yield_now().await; + tokio::task::yield_now().await; } }; diff --git a/examples/src/phaser_completion.rs b/examples/src/phaser_completion.rs index fca613f6..a1da43f9 100644 --- a/examples/src/phaser_completion.rs +++ b/examples/src/phaser_completion.rs @@ -36,7 +36,6 @@ use std::sync::atomic::Ordering; use asyncband::phaser::Closed; use asyncband::phaser::Phaser; use asyncband::phaser::PhaserParticipant; -use tokio::task::yield_now; // Own this guard before constructing a task future so cancelling an unpolled task also aborts. struct CloseOnDrop([Phaser; 2]); @@ -114,7 +113,7 @@ async fn publish_until_target() -> Result<(), Closed> { .map(|value| value.load(Ordering::Relaxed)) .sum(); // An async checkpoint can be awaited here while workers wait at resume. - yield_now().await; + tokio::task::yield_now().await; published.store(sum, Ordering::Relaxed); println!("coordinator: published aggregate {sum}"); if sum >= 18 { diff --git a/examples/src/phaser_rounds.rs b/examples/src/phaser_rounds.rs index a2a0f162..2b39d87b 100644 --- a/examples/src/phaser_rounds.rs +++ b/examples/src/phaser_rounds.rs @@ -30,7 +30,6 @@ use std::future::ready; use asyncband::phaser::Closed; use asyncband::phaser::Phaser; use asyncband::phaser::PhaserParticipant; -use tokio::task::yield_now; #[tokio::main(flavor = "current_thread")] async fn main() -> Result<(), Closed> { @@ -65,7 +64,7 @@ async fn work(mut participant: PhaserParticipant, rounds: usize) -> Result<(), C for _ in 0..rounds { let observed = participant.arrive()?; // This work does not hold up the other participants' arrivals. - yield_now().await; + tokio::task::yield_now().await; let next = participant.wait().await?; assert_ne!(observed, next); } diff --git a/examples/src/shared_completion.rs b/examples/src/shared_completion.rs index 0e1a32a5..5570b1ff 100644 --- a/examples/src/shared_completion.rs +++ b/examples/src/shared_completion.rs @@ -24,7 +24,6 @@ use std::ptr; use asyncband::completion; -use tokio::task::yield_now; #[tokio::main(flavor = "current_thread")] async fn main() { @@ -33,7 +32,7 @@ async fn main() { let audit_log = completion.clone(); let worker = tokio::spawn(async move { - yield_now().await; + tokio::task::yield_now().await; completer .complete(String::from("build 42 succeeded")) .unwrap(); diff --git a/tests-integration/tests/condvar_test.rs b/tests-integration/tests/condvar_test.rs index 69572d27..4c2174e4 100644 --- a/tests-integration/tests/condvar_test.rs +++ b/tests-integration/tests/condvar_test.rs @@ -27,7 +27,6 @@ use tests_integration::poll_once; use tests_integration::poll_with; use tests_integration::test_runtime; use tokio::task::JoinHandle; -use tokio::task::yield_now; struct NotifyOnDrop(Arc); @@ -145,7 +144,7 @@ fn notify_all_wakes_current_waiters_using_a_predicate_loop() { break; } drop(state); - yield_now().await; + tokio::task::yield_now().await; } // Seeing every task's `waiting` update while holding this mutex also means every task has diff --git a/tests-integration/tests/lazy_cell_test.rs b/tests-integration/tests/lazy_cell_test.rs index e056eb93..d08f4bef 100644 --- a/tests-integration/tests/lazy_cell_test.rs +++ b/tests-integration/tests/lazy_cell_test.rs @@ -29,7 +29,6 @@ use std::task::Poll; use asyncband::once::LazyCell; use tokio::sync::Notify; -use tokio::task::yield_now; struct DropPanic; @@ -67,7 +66,7 @@ async fn concurrent_force_runs_initializer_once() { move || { Box::pin(async move { attempts.fetch_add(1, Ordering::SeqCst); - yield_now().await; + tokio::task::yield_now().await; 42 }) } @@ -408,7 +407,7 @@ async fn inline_future_supports_local_non_send_state() { let lazy = LazyCell::new({ let local = Rc::clone(&local); async move || { - yield_now().await; + tokio::task::yield_now().await; *local + 1 } }); diff --git a/tests-integration/tests/mpmc_test/concurrency.rs b/tests-integration/tests/mpmc_test/concurrency.rs index db336be0..dbcbede8 100644 --- a/tests-integration/tests/mpmc_test/concurrency.rs +++ b/tests-integration/tests/mpmc_test/concurrency.rs @@ -20,7 +20,6 @@ use std::time::Duration; use asyncband::mpmc; use tokio::task::JoinHandle; -use tokio::time::timeout; use crate::Receiver; @@ -53,7 +52,7 @@ where .collect::>(); drop(receiver); - let mut received = timeout(Duration::from_secs(10), async { + let mut received = tokio::time::timeout(Duration::from_secs(10), async { for producer in producers { producer.await.unwrap(); } diff --git a/tests-integration/tests/mpsc_test/concurrency.rs b/tests-integration/tests/mpsc_test/concurrency.rs index 7b753b71..24facfd4 100644 --- a/tests-integration/tests/mpsc_test/concurrency.rs +++ b/tests-integration/tests/mpsc_test/concurrency.rs @@ -37,7 +37,6 @@ use tests_integration::poll_once; use tests_integration::poll_with; use tests_integration::test_runtime; use tokio::sync::oneshot; -use tokio::task::yield_now; use tokio_test::assert_ok; #[test] @@ -330,22 +329,22 @@ async fn selection_preserves_messages_across_cancelled_receives() { tokio::spawn(async move { assert_ok!(tx2.send(1)); - yield_now().await; + tokio::task::yield_now().await; assert_ok!(tx1.send(2)); - yield_now().await; + tokio::task::yield_now().await; assert_ok!(tx2.send(3)); - yield_now().await; + tokio::task::yield_now().await; assert_ok!(tx3.send(4).await); - yield_now().await; + tokio::task::yield_now().await; assert_ok!(tx4.send(5).await); - yield_now().await; + tokio::task::yield_now().await; assert_ok!(tx3.send(6).await); - yield_now().await; + tokio::task::yield_now().await; drop((tx1, tx2)); }); diff --git a/tests-integration/tests/mutex_test.rs b/tests-integration/tests/mutex_test.rs index 7f1c5f79..62b2baf1 100644 --- a/tests-integration/tests/mutex_test.rs +++ b/tests-integration/tests/mutex_test.rs @@ -22,7 +22,6 @@ use std::task::Poll; use asyncband::mutex::*; use tests_integration::poll_once; -use tokio::task::yield_now; #[test] fn test_try_lock_never_blocks() { @@ -179,7 +178,7 @@ async fn test_mapped_mutex_guard_send() { let guard = mutex_clone.lock().await; let mapped_guard = MutexGuard::map(guard, |data| &mut data.field1); - yield_now().await; + tokio::task::yield_now().await; *mapped_guard }); diff --git a/tests-integration/tests/phaser_test.rs b/tests-integration/tests/phaser_test.rs index aaef6e91..15900ac4 100644 --- a/tests-integration/tests/phaser_test.rs +++ b/tests-integration/tests/phaser_test.rs @@ -27,7 +27,6 @@ use tests_integration::poll_once; use tests_integration::poll_with; use tests_integration::waker_on_drop; use tokio::sync::oneshot; -use tokio::task::yield_now; #[test] fn batch_registration_joins_one_observed_phase() { @@ -625,7 +624,7 @@ async fn participant_can_wait_from_a_spawned_task() { let first_wait = tokio::spawn(async move { first.wait().await }); - yield_now().await; + tokio::task::yield_now().await; let phase = second.arrive().unwrap(); assert_eq!(first_wait.await.unwrap().unwrap(), phaser.phase()); assert_ne!(phase, phaser.phase()); @@ -641,7 +640,7 @@ async fn observer_waits_without_becoming_a_party() { let observer_phaser = phaser.clone(); let observer = tokio::spawn(async move { observer_phaser.wait(observed).await }); - yield_now().await; + tokio::task::yield_now().await; assert_eq!(phaser.registered_parties(), 2); first.arrive().unwrap(); second.deregister().unwrap(); diff --git a/tests-integration/tests/rwlock_test.rs b/tests-integration/tests/rwlock_test.rs index f5518655..ca30f49c 100644 --- a/tests-integration/tests/rwlock_test.rs +++ b/tests-integration/tests/rwlock_test.rs @@ -22,7 +22,6 @@ use std::sync::Arc; use asyncband::rwlock::*; use tests_integration::poll_once; use tokio::sync::Barrier; -use tokio::task::yield_now; use tokio_test::assert_pending; use tokio_test::assert_ready; @@ -81,7 +80,7 @@ async fn concurrent_readers_and_writers_preserve_values() { readers.push(tokio::spawn(async move { start.wait().await; let value = *rwlock.read().await; - yield_now().await; + tokio::task::yield_now().await; value })); } @@ -93,7 +92,7 @@ async fn concurrent_readers_and_writers_preserve_values() { start.wait().await; let mut guard = rwlock.write().await; *guard += 1; - yield_now().await; + tokio::task::yield_now().await; })); } @@ -424,7 +423,7 @@ async fn aborted_task_releases_its_owned_mapped_rwlock_guard() { }); assert!(rwlock.try_read().is_none()); - yield_now().await; + tokio::task::yield_now().await; task.abort(); assert!(task.await.unwrap_err().is_cancelled()); assert_eq!(*rwlock.try_read().unwrap(), [10, 2]); diff --git a/tests-integration/tests/spmc_test/concurrency.rs b/tests-integration/tests/spmc_test/concurrency.rs index 30c3558f..d44ba4d1 100644 --- a/tests-integration/tests/spmc_test/concurrency.rs +++ b/tests-integration/tests/spmc_test/concurrency.rs @@ -21,7 +21,6 @@ use std::time::Duration; use asyncband::spmc; use tokio::sync::Barrier; use tokio::task::JoinHandle; -use tokio::time::timeout; const CONSUMERS: usize = 8; const TOTAL: usize = 2_048; @@ -30,7 +29,7 @@ async fn assert_delivered_exactly_once( producer: JoinHandle<()>, consumers: Vec>>, ) { - timeout(Duration::from_secs(10), async { + tokio::time::timeout(Duration::from_secs(10), async { producer.await.unwrap(); let mut received = Vec::with_capacity(TOTAL); for consumer in consumers { From 5ba5e0d1bc6308caed767fb9e6a4e62da0681e24 Mon Sep 17 00:00:00 2001 From: tison Date: Sun, 11 Oct 2026 14:28:51 +0100 Subject: [PATCH 7/8] refactor: export MPMC permits from their defining module --- asyncband/src/mpmc/bounded.rs | 2 +- asyncband/src/mpmc/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/asyncband/src/mpmc/bounded.rs b/asyncband/src/mpmc/bounded.rs index c3f0bf6a..84f19e23 100644 --- a/asyncband/src/mpmc/bounded.rs +++ b/asyncband/src/mpmc/bounded.rs @@ -22,7 +22,7 @@ use crate::mpmc::RecvError; use crate::mpmc::SendError; use crate::mpmc::TryRecvError; use crate::mpmc::TrySendError; -pub use crate::mpmc::queue::Permit; +use crate::mpmc::queue::Permit; use crate::mpmc::queue::Shared; /// Creates a bounded multi-producer, multi-consumer queue. diff --git a/asyncband/src/mpmc/mod.rs b/asyncband/src/mpmc/mod.rs index ebb03a0c..ba484949 100644 --- a/asyncband/src/mpmc/mod.rs +++ b/asyncband/src/mpmc/mod.rs @@ -29,12 +29,12 @@ mod unbounded; pub use self::bounded::BoundedReceiver; pub use self::bounded::BoundedSender; -pub use self::bounded::Permit; pub use self::bounded::bounded; pub use self::error::RecvError; pub use self::error::SendError; pub use self::error::TryRecvError; pub use self::error::TrySendError; +pub use self::queue::Permit; pub use self::unbounded::UnboundedReceiver; pub use self::unbounded::UnboundedSender; pub use self::unbounded::unbounded; From ad9ee7eec3e2ab2b37dea3ca17c1cb11126acfee Mon Sep 17 00:00:00 2001 From: tison Date: Sun, 11 Oct 2026 14:35:32 +0100 Subject: [PATCH 8/8] style: restore the original xtask imports --- xtask/src/main.rs | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/xtask/src/main.rs b/xtask/src/main.rs index b48b97f1..a047a4f4 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -16,7 +16,7 @@ // under the License. use std::path::Path; -use std::process; +use std::process::Command as StdCommand; use std::process::ExitStatus; use std::time::Duration; @@ -24,7 +24,6 @@ use clap::Parser; use clap::Subcommand; use semver::Version; use serde::Deserialize; -use ureq::Agent; const PACKAGE_NAME: &str = "asyncband"; // cargo-semver-checks reserves exit code 100 for completed checks that found deny-level violations. @@ -285,10 +284,10 @@ impl SemverReleaseType { } } -fn find_command(cmd: &str) -> process::Command { +fn find_command(cmd: &str) -> StdCommand { match which::which(cmd) { Ok(exe) => { - let mut cmd = process::Command::new(exe); + let mut cmd = StdCommand::new(exe); cmd.current_dir(env!("CARGO_WORKSPACE_DIR")); cmd } @@ -306,19 +305,19 @@ fn ensure_installed(bin: &str, crate_name: &str) { } } -fn run_command(cmd: process::Command) { +fn run_command(cmd: StdCommand) { let status = command_status(cmd); assert!(status.success(), "command failed: {status}"); } -fn command_status(mut cmd: process::Command) -> ExitStatus { +fn command_status(mut cmd: StdCommand) -> ExitStatus { println!("{cmd:?}"); cmd.status().expect("failed to execute process") } fn find_latest_release() -> Option { - let agent = Agent::from( - Agent::config_builder() + let agent = ureq::Agent::from( + ureq::Agent::config_builder() .timeout_global(Some(Duration::from_secs(10))) .build(), ); @@ -380,7 +379,7 @@ fn classify_release_type(baseline: &Version, release: &Version) -> SemverRelease } } -fn make_bench_cmd(no_run: bool, bench: Option<&str>, args: &[String]) -> process::Command { +fn make_bench_cmd(no_run: bool, bench: Option<&str>, args: &[String]) -> StdCommand { let mut cmd = find_command("cargo"); cmd.args([ "bench", @@ -398,7 +397,7 @@ fn make_bench_cmd(no_run: bool, bench: Option<&str>, args: &[String]) -> process cmd } -fn make_build_cmd(locked: bool) -> process::Command { +fn make_build_cmd(locked: bool) -> StdCommand { let mut cmd = find_command("cargo"); cmd.args([ "build", @@ -415,7 +414,7 @@ fn make_build_cmd(locked: bool) -> process::Command { cmd } -fn make_test_cmd(no_capture: bool, features: &[String]) -> process::Command { +fn make_test_cmd(no_capture: bool, features: &[String]) -> StdCommand { let mut cmd = find_command("cargo"); cmd.args(["test", "--workspace", "--no-default-features"]); for feature in features { @@ -427,7 +426,7 @@ fn make_test_cmd(no_capture: bool, features: &[String]) -> process::Command { cmd } -fn make_check_cmd(features: &[String]) -> process::Command { +fn make_check_cmd(features: &[String]) -> StdCommand { let mut cmd = find_command("cargo"); cmd.env("RUSTFLAGS", "-Dwarnings"); cmd.args([ @@ -444,14 +443,14 @@ fn make_check_cmd(features: &[String]) -> process::Command { cmd } -fn make_miri_cmd(package: &str, target: &[&str]) -> process::Command { +fn make_miri_cmd(package: &str, target: &[&str]) -> StdCommand { let mut cmd = find_command("cargo"); cmd.args(["+nightly", "miri", "test", "--package", package]); cmd.args(target); cmd } -fn make_format_cmd(fix: bool) -> process::Command { +fn make_format_cmd(fix: bool) -> StdCommand { let mut cmd = find_command("cargo"); cmd.args(["+nightly", "fmt", "--all"]); if !fix { @@ -460,7 +459,7 @@ fn make_format_cmd(fix: bool) -> process::Command { cmd } -fn make_clippy_cmd(fix: bool) -> process::Command { +fn make_clippy_cmd(fix: bool) -> StdCommand { let mut cmd = find_command("cargo"); cmd.args([ "+nightly", @@ -478,7 +477,7 @@ fn make_clippy_cmd(fix: bool) -> process::Command { cmd } -fn make_doc_cmd() -> process::Command { +fn make_doc_cmd() -> StdCommand { let mut cmd = find_command("cargo"); cmd.env("RUSTDOCFLAGS", "-D warnings --cfg docsrs"); cmd.args([ @@ -494,7 +493,7 @@ fn make_doc_cmd() -> process::Command { fn make_semver_check_cmd( baseline_version: &Version, release_type: SemverReleaseType, -) -> process::Command { +) -> StdCommand { ensure_installed("cargo-semver-checks", "cargo-semver-checks"); let mut cmd = find_command("cargo"); cmd.args([ @@ -511,7 +510,7 @@ fn make_semver_check_cmd( cmd } -fn make_hawkeye_cmd(fix: bool) -> process::Command { +fn make_hawkeye_cmd(fix: bool) -> StdCommand { ensure_installed("hawkeye", "hawkeye"); let mut cmd = find_command("hawkeye"); if fix { @@ -522,12 +521,12 @@ fn make_hawkeye_cmd(fix: bool) -> process::Command { cmd } -fn make_typos_cmd() -> process::Command { +fn make_typos_cmd() -> StdCommand { ensure_installed("typos", "typos-cli"); find_command("typos") } -fn make_taplo_cmd(fix: bool) -> process::Command { +fn make_taplo_cmd(fix: bool) -> StdCommand { ensure_installed("taplo", "taplo-cli"); let mut cmd = find_command("taplo"); if fix {