use super::{Completion, File, WriteCompletion, IO}; use anyhow::{Ok, Result}; use std::rc::Rc; use std::cell::RefCell; use std::io::{Read, Seek, Write}; use log::trace; pub struct WindowsIO {} impl WindowsIO { pub fn new() -> Result { Ok(Self {}) } } impl IO for WindowsIO { fn open_file(&self, path: &str) -> Result> { trace!("open_file(path = {})", path); let file = std::fs::File::open(path)?; Ok(Rc::new(WindowsFile { file: RefCell::new(file), })) } fn run_once(&self) -> Result<()> { Ok(()) } } pub struct WindowsFile { file: RefCell, } impl File for WindowsFile { fn pread(&self, pos: usize, c: Rc) -> Result<()> { let mut file = self.file.borrow_mut(); file.seek(std::io::SeekFrom::Start(pos as u64))?; { let mut buf = c.buf_mut(); let buf = buf.as_mut_slice(); file.read_exact(buf)?; } c.complete(); Ok(()) } fn pwrite( &self, pos: usize, buffer: Rc>, c: Rc, ) -> Result<()> { let mut file = self.file.borrow_mut(); file.seek(std::io::SeekFrom::Start(pos as u64))?; let buf = buffer.borrow(); let buf = buf.as_slice(); file.write_all(buf)?; Ok(()) } }