io_trait/
async_io.rs

1use std::{ffi::CStr, io};
2
3#[derive(Debug)]
4pub enum OperationResult {
5    Ok(usize),
6    Pending,
7    Err(io::Error),
8}
9
10pub trait AsyncOperation {
11    fn get_result(&mut self) -> OperationResult;
12}
13
14pub trait AsyncFile {
15    type Operation<'a>: AsyncOperation
16    where
17        Self: 'a;
18    fn read<'a>(&'a mut self, offset: u64, buffer: &'a mut [u8])
19        -> io::Result<Self::Operation<'a>>;
20    fn write<'a>(&'a mut self, offset: u64, buffer: &'a [u8]) -> io::Result<Self::Operation<'a>>;
21}
22
23pub trait AsyncIo {
24    type File: AsyncFile;
25    fn create(&self, path: &CStr) -> io::Result<Self::File>;
26    fn open(&self, path: &CStr) -> io::Result<Self::File>;
27}