base_scheduler/file_operation.rs
1// Released under the MIT License.
2// Copyright, 2026, by Samuel Williams.
3
4/// Shared resource type for file operations provided by a scheduler.
5///
6/// Implement this trait on the scheduler, not the descriptor. All file operation traits use this one associated type, allowing generic consumers to combine capabilities without resource-type equality bounds. Implementations choose their own representation; no OS descriptor or shared-ownership wrapper is required by the interface.
7///
8/// A submitted operation must retain every resource and buffer it can still access, even if its waiting future is dropped. Applications finish outstanding work before explicitly closing a resource; close never cancels or joins other operations.
9///
10/// Implementations document resource compatibility, including affinity to particular scheduler instances. Successive operations may use different compatible instances. Incompatible pairings must be rejected with `std::io::ErrorKind::InvalidInput` before submission when the type system cannot reject them. Rebinding or conversion is an explicit backend operation. Bound reader and writer handles fix their compatible scheduler at construction; per-operation calls do not rebind them.
11///
12/// Selecting a resource type does not supply any operations:
13///
14/// ```compile_fail,E0599
15/// use base_scheduler::{Cancellation, FileOperation};
16/// async fn read<S: FileOperation>(scheduler: &S, file: &S::File) {
17/// scheduler.file_reader(file);
18/// }
19/// ```
20pub trait FileOperation: Send + Sync {
21 /// The file resource accepted by this scheduler's file operations.
22 type File: Send + Sync;
23}