diff --git a/.spelling b/.spelling index 745abe2cc..3719e2dd4 100644 --- a/.spelling +++ b/.spelling @@ -132,6 +132,7 @@ HRESULT https i.e. impl +Implementors impls infeasible inlined diff --git a/crates/anyspawn/src/spawner.rs b/crates/anyspawn/src/spawner.rs index 4adc60ab4..910995a8f 100644 --- a/crates/anyspawn/src/spawner.rs +++ b/crates/anyspawn/src/spawner.rs @@ -33,7 +33,7 @@ use crate::handle::JoinHandleInner; /// println!("Task running!"); /// }); /// handle.await; // Wait for task to complete -/// +/// /// # } /// ``` /// diff --git a/crates/bytesbuf_io/src/concurrent_read.rs b/crates/bytesbuf_io/src/concurrent_read.rs new file mode 100644 index 000000000..f9f3dafd4 --- /dev/null +++ b/crates/bytesbuf_io/src/concurrent_read.rs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +use std::fmt::Debug; + +use bytesbuf::mem::{HasMemory, Memory}; + +use crate::Read; + +/// Allows a [`Read`] source to support multiple concurrent read operations. +/// +/// The [`Read`] trait takes `&mut self`, limiting callers to one read at a time. +/// Some I/O endpoints can support many reads in flight simultaneously for higher throughput. +/// +/// Implementors return a new independent [`Read`] handle from each call to [`concurrently()`], +/// enabling the caller to drive any number of reads in parallel. +/// +/// [`concurrently()`]: ConcurrentRead::concurrently +pub trait ConcurrentRead: HasMemory + Memory + Debug { + /// The type of [`Read`] handle returned by [`concurrently()`](ConcurrentRead::concurrently). + type Handle: Read + Send + 'static; + + /// Returns a new independent [`Read`] handle that can execute one concurrent read. + /// + /// Each handle operates independently - multiple handles may have reads in flight at the + /// same time without interfering with each other. + fn concurrently(&self) -> Self::Handle; +} diff --git a/crates/bytesbuf_io/src/concurrent_write.rs b/crates/bytesbuf_io/src/concurrent_write.rs new file mode 100644 index 000000000..82d6c610b --- /dev/null +++ b/crates/bytesbuf_io/src/concurrent_write.rs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +use std::fmt::Debug; + +use bytesbuf::mem::{HasMemory, Memory}; + +use crate::Write; + +/// Allows a [`Write`] sink to support multiple concurrent write operations. +/// +/// The [`Write`] trait takes `&mut self`, limiting callers to one write at a time. +/// Some I/O endpoints can support many writes in flight simultaneously for higher throughput. +/// +/// Implementors return a new independent [`Write`] handle from each call to [`concurrently()`], +/// enabling the caller to drive any number of writes in parallel. +/// +/// [`concurrently()`]: ConcurrentWrite::concurrently +pub trait ConcurrentWrite: HasMemory + Memory + Debug { + /// The type of [`Write`] handle returned by [`concurrently()`](ConcurrentWrite::concurrently). + type Handle: Write + Send + 'static; + + /// Returns a new independent [`Write`] handle that can execute one concurrent write. + /// + /// Each handle operates independently - multiple handles may have writes in flight at the + /// same time without interfering with each other. + fn concurrently(&self) -> Self::Handle; +} diff --git a/crates/bytesbuf_io/src/lib.rs b/crates/bytesbuf_io/src/lib.rs index 3c4c3d186..3c627141d 100644 --- a/crates/bytesbuf_io/src/lib.rs +++ b/crates/bytesbuf_io/src/lib.rs @@ -25,6 +25,8 @@ #![doc(html_logo_url = "https://media.githubusercontent.com/media/microsoft/oxidizer/refs/heads/main/crates/bytesbuf_io/logo.png")] #![doc(html_favicon_url = "https://media.githubusercontent.com/media/microsoft/oxidizer/refs/heads/main/crates/bytesbuf_io/favicon.ico")] +mod concurrent_read; +mod concurrent_write; mod error; mod read; mod read_ext; @@ -33,6 +35,8 @@ mod read_futures; mod write; mod write_ext; +pub use concurrent_read::ConcurrentRead; +pub use concurrent_write::ConcurrentWrite; pub use error::{Error, Result}; pub use read::Read; pub use read_ext::{ReadExt, ReadInspectDecision};