Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ 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 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::...` 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.

## Waker Contract

Expand Down
2 changes: 1 addition & 1 deletion asyncband/src/blocking/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<F: IntoFuture>(future: F) -> F::Output {
let mut future = pin!(future.into_future());
Expand Down
4 changes: 2 additions & 2 deletions asyncband/src/blocking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down
12 changes: 6 additions & 6 deletions asyncband/src/broadcast/mpmc/bounded/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 3 additions & 5 deletions asyncband/src/broadcast/mpmc/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -531,9 +531,7 @@ pub fn take_msg<T: Clone>(msg: Arc<T>, reclaimed: Reclaimed<T>) -> T {

#[cfg(test)]
mod tests {
use std::sync::Arc;

use super::Backlog;
use super::*;

/// Drives every cursor-count mutation point — subscribing, publishing, receiving, and dropping
/// — and checks the accounting after each step.
Expand Down
7 changes: 4 additions & 3 deletions asyncband/src/broadcast/mpmc/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`].
Expand Down Expand Up @@ -65,7 +66,7 @@ impl<T> fmt::Debug for TrySendError<T> {
}
}

impl<T> std::error::Error for TrySendError<T> {}
impl<T> Error for TrySendError<T> {}

/// Error returned by `recv`.
#[derive(Debug, Clone, PartialEq, Eq)]
Expand All @@ -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)]
Expand All @@ -100,4 +101,4 @@ impl fmt::Display for TryRecvError {
}
}

impl std::error::Error for TryRecvError {}
impl Error for TryRecvError {}
12 changes: 6 additions & 6 deletions asyncband/src/broadcast/mpmc/unbounded/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion asyncband/src/completion/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
//! # }
//! ```

use std::error::Error;
use std::fmt;
use std::future::Future;
use std::mem;
Expand Down Expand Up @@ -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.
///
Expand Down
4 changes: 2 additions & 2 deletions asyncband/src/event/auto_reset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down
5 changes: 3 additions & 2 deletions asyncband/src/internal/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// specific language governing permissions and limitations
// under the License.

use std::fmt;
use std::mem;
use std::num::NonZeroUsize;

Expand All @@ -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()
}
}
Expand Down
2 changes: 0 additions & 2 deletions asyncband/src/internal/semaphore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
3 changes: 1 addition & 2 deletions asyncband/src/internal/waker_batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,8 @@ mod tests {
use std::sync::Arc;
use std::sync::Mutex;
use std::task::Wake;
use std::task::Waker;

use super::WakerBatch;
use super::*;

const STACK_SIZE: usize = WakerBatch::STACK_SIZE;

Expand Down
2 changes: 1 addition & 1 deletion asyncband/src/internal/wakerset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl WakerSet {

#[cfg(test)]
mod tests {
use super::WakerToken;
use super::*;

#[test]
fn waker_token_preserves_the_option_niche() {
Expand Down
16 changes: 9 additions & 7 deletions asyncband/src/mpmc/bounded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
use crate::mpmc::queue::Permit;
use crate::mpmc::queue::Shared;

/// Creates a bounded multi-producer, multi-consumer queue.
///
Expand Down Expand Up @@ -108,7 +108,9 @@ impl<T> BoundedSender<T> {
/// ```
/// # #[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();
Expand Down
9 changes: 5 additions & 4 deletions asyncband/src/mpmc/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -52,7 +53,7 @@ impl<T> fmt::Debug for SendError<T> {
}
}

impl<T> std::error::Error for SendError<T> {}
impl<T> Error for SendError<T> {}

/// Error returned by [`BoundedSender::try_send`](crate::mpmc::BoundedSender::try_send) or
/// [`BoundedSender::try_reserve`](crate::mpmc::BoundedSender::try_reserve).
Expand Down Expand Up @@ -101,7 +102,7 @@ impl<T> fmt::Debug for TrySendError<T> {
}
}

impl<T> std::error::Error for TrySendError<T> {}
impl<T> Error for TrySendError<T> {}

/// Error returned when receiving a value fails.
#[derive(Debug, Clone, PartialEq, Eq)]
Expand All @@ -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)]
Expand All @@ -136,4 +137,4 @@ impl fmt::Display for TryRecvError {
}
}

impl std::error::Error for TryRecvError {}
impl Error for TryRecvError {}
2 changes: 1 addition & 1 deletion asyncband/src/mpmc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
8 changes: 4 additions & 4 deletions asyncband/src/mpmc/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
state: Mutex<State<T>>,
Expand Down
10 changes: 5 additions & 5 deletions asyncband/src/mpmc/unbounded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
2 changes: 1 addition & 1 deletion asyncband/src/mpsc/bounded/receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
8 changes: 5 additions & 3 deletions asyncband/src/mpsc/bounded/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -117,7 +117,9 @@ impl<T> BoundedSender<T> {
/// ```
/// # #[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();
Expand Down
Loading
Loading