mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-23 03:04:19 +01:00
37 lines
670 B
Rust
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<()>;
|
|
}
|