Skip to content

Commit e315ae1

Browse files
authored
feat(io): read-multi traits (#732)
* feat(io): traits for async read multi * docs(io): managed & multi read * feat(io): use new managed traits * docs(io): fix broken links * docs(io): `len` is for each time
1 parent d71661e commit e315ae1

3 files changed

Lines changed: 45 additions & 0 deletions

File tree

compio-io/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@
1616
//! - [`BufReader`]: An async reader with internal buffer
1717
//! - [`BufWriter`]: An async writer with internal buffer
1818
//!
19+
//! ### Managed IO
20+
//!
21+
//! - [`AsyncReadManaged`]: Async read with a managed buffer
22+
//! - [`AsyncReadManagedAt`]: Async read with a managed buffer and offset
23+
//! - [`AsyncReadMulti`]: Async read, and returns a stream of multiple managed
24+
//! buffers
25+
//! - [`AsyncReadMultiAt`]: Async read with offset, and returns a stream of
26+
//! multiple managed buffers
27+
//!
1928
//! ### Extension
2029
//!
2130
//! - [`AsyncReadExt`]: Extension trait for [`AsyncRead`]

compio-io/src/read/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ mod buf;
88
#[macro_use]
99
mod ext;
1010
mod managed;
11+
mod multi;
1112

1213
pub use buf::*;
1314
pub use ext::*;
1415
pub use managed::*;
16+
pub use multi::*;
1517

1618
use crate::util::{slice_to_buf, slice_to_uninit};
1719

compio-io/src/read/multi.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use futures_util::Stream;
2+
3+
use crate::{AsyncReadManaged, AsyncReadManagedAt, IoResult};
4+
5+
/// # AsyncReadMulti
6+
///
7+
/// Async read with buffer pool and returns a stream of managed buffers.
8+
pub trait AsyncReadMulti: AsyncReadManaged {
9+
/// Read some bytes from this source and return a stream of
10+
/// [`AsyncReadManaged::Buffer`].
11+
///
12+
/// # Implementation Note
13+
///
14+
/// - If `len` == 0, implementation should use buffer's size as `len`
15+
/// - if `len` > 0, `min(len, buffer_size)` will be the max number of bytes
16+
/// to be read each time.
17+
fn read_multi(&mut self, len: usize) -> impl Stream<Item = IoResult<Self::Buffer>>;
18+
}
19+
20+
/// # AsyncReadMultiAt
21+
///
22+
/// Async read with buffer pool and position, returns a stream of managed
23+
/// buffers.
24+
pub trait AsyncReadMultiAt: AsyncReadManagedAt {
25+
/// Read some bytes from this source at position and return a stream of
26+
/// [`AsyncReadManagedAt::Buffer`].
27+
///
28+
/// # Implementation Note
29+
///
30+
/// - If `len` == 0, implementation should use buffer's size as `len`
31+
/// - if `len` > 0, `min(len, buffer_size)` will be the max number of bytes
32+
/// to be read each time.
33+
fn read_multi_at(&self, len: usize, pos: u64) -> impl Stream<Item = IoResult<Self::Buffer>>;
34+
}

0 commit comments

Comments
 (0)