1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Released under the MIT License.
// Copyright, 2026, by Samuel Williams.
use crate::{BufferResult, Cancellation, IoBufMut};
use std::{future::Future, io};
/// Scheduler-bound, sequential access to a file's readable direction. Construct through [`FileReading`](crate::FileReading). Separate handles permit overlapping operations, but shared-cursor operations have no ordering guarantee across handles.
pub trait FileReader: Send {
/// Read once at the file's shared OS cursor, returning a possibly short count and the original owner on every result. Cancellation cannot roll back transferred bytes or cursor changes.
fn read<B: IoBufMut>(
&mut self,
buffer: B,
cancellation: &Cancellation,
) -> impl Future<Output = BufferResult<B>> + Send;
/// Read once at an explicit offset. Offsets must fit in `i64`. Unix implementations leave the shared cursor unchanged; Windows implementations may use `seek_read`, which changes it. The handle maintains no private cursor.
fn read_at<B: IoBufMut>(
&mut self,
buffer: B,
offset: u64,
cancellation: &Cancellation,
) -> impl Future<Output = BufferResult<B>> + Send;
/// Await admission separately from collecting the original owner. Accepted work can complete independently of polling the returned future. The fallback completes the ordinary operation before returning; backends can admit independently progressing work earlier. Pre-cancellation rejects admission and returns the unchanged owner.
fn read_submit<B: IoBufMut>(
&mut self,
buffer: B,
cancellation: &Cancellation,
) -> impl Future<
Output = Result<
impl Future<Output = BufferResult<B>> + Send + 'static,
(crate::OperationError, B),
>,
> + Send {
async move {
if let Err(error) = cancellation.check() {
return Err((error.into(), buffer));
}
let result = self.read(buffer, cancellation).await;
Ok(async move { result })
}
}
/// Await admission separately from collecting the original owner. Accepted work can complete independently of polling the returned future. The fallback completes the ordinary operation before returning; backends can admit independently progressing work earlier. Pre-cancellation rejects admission and returns the unchanged owner.
fn read_at_submit<B: IoBufMut>(
&mut self,
buffer: B,
offset: u64,
cancellation: &Cancellation,
) -> impl Future<
Output = Result<
impl Future<Output = BufferResult<B>> + Send + 'static,
(crate::OperationError, B),
>,
> + Send {
async move {
if let Err(error) = cancellation.check() {
return Err((error.into(), buffer));
}
let result = self.read_at(buffer, offset, cancellation).await;
Ok(async move { result })
}
}
/// Stop admission and await accepted operation retirement without cancellation. Repeated close is safe; dropping a pending close is not a retirement barrier. This does not close the underlying file. Drop the retired handle before exclusive file close.
fn close(&mut self) -> impl Future<Output = io::Result<()>> + Send;
}