use std::fs::OpenOptions;
use std::io;
use std::os::unix::prelude::*;
use std::path::PathBuf;
use async_trait::async_trait;
#[async_trait]
pub trait AioOpenOptionsExt {
async fn aio_open(mut self, path: PathBuf, is_sync: bool) -> io::Result<crate::fs::File>;
}
#[async_trait]
impl AioOpenOptionsExt for OpenOptions {
async fn aio_open(mut self, path: PathBuf, is_sync: bool) -> io::Result<crate::fs::File> {
self.custom_flags(libc::O_DIRECT);
if is_sync {
self.custom_flags(libc::O_SYNC);
}
let tokio_file = tokio::fs::OpenOptions::from(self).open(path).await?;
Ok(crate::fs::File { inner: tokio_file })
}
}