Files
turso/core/io/mod.rs
Pekka Enberg fe41f46bc0 I/O trait
2023-09-10 21:57:36 +03:00

37 lines
670 B
Rust

use anyhow::Result;
use std::sync::Arc;
#[cfg(target_os = "linux")]
mod linux;
#[cfg(target_os = "macos")]
mod darwin;
pub trait IO {
fn open(&self, path: &str) -> Result<PageSource>;
}
#[cfg(target_os = "linux")]
pub fn default_io() -> Result<impl IO> {
Ok(linux::LinuxIO::new()?)
}
#[cfg(target_os = "macos")]
pub fn default_io() -> Result<impl IO> {
Ok(darwin::DarwinIO::new()?)
}
pub struct PageSource {
io: Arc<dyn PageIO>,
}
impl PageSource {
pub fn get(&self, page_idx: usize, buf: &mut [u8]) -> Result<()> {
self.io.get(page_idx, buf)
}
}
trait PageIO {
fn get(&self, page_idx: usize, buf: &mut [u8]) -> Result<()>;
}