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
use std::{ffi::CStr, io};

#[derive(Debug)]
pub enum OperationResult {
    Ok(usize),
    Pending,
    Err(io::Error),
}

pub trait AsyncOperation {
    fn get_result(&mut self) -> OperationResult;
}

pub trait AsyncFile {
    type Operation<'a>: AsyncOperation
    where
        Self: 'a;
    fn read<'a>(&'a mut self, offset: u64, buffer: &'a mut [u8])
        -> io::Result<Self::Operation<'a>>;
    fn write<'a>(&'a mut self, offset: u64, buffer: &'a [u8]) -> io::Result<Self::Operation<'a>>;
}

pub trait AsyncIo {
    type File: AsyncFile;
    fn create(&self, path: &CStr) -> io::Result<Self::File>;
    fn open(&self, path: &CStr) -> io::Result<Self::File>;
}