use std::path::Path;
use crate::error::{Error, Result};
pub trait IoBackend: Send + Sync {
fn read(&self, path: &Path) -> Result<Vec<u8>>;
fn name(&self) -> &'static str;
}
#[derive(Debug, Default, Clone, Copy)]
pub struct RayonBackend;
impl IoBackend for RayonBackend {
fn read(&self, path: &Path) -> Result<Vec<u8>> {
std::fs::read(path).map_err(|e| Error::io(path, e))
}
fn name(&self) -> &'static str {
"rayon"
}
}
#[cfg(all(feature = "io-uring", target_os = "linux"))]
mod uring {
use super::*;
#[derive(Debug, Default, Clone, Copy)]
pub struct UringBackend;
impl IoBackend for UringBackend {
fn read(&self, path: &Path) -> Result<Vec<u8>> {
std::fs::read(path).map_err(|e| Error::io(path, e))
}
fn name(&self) -> &'static str {
"io_uring"
}
}
}
pub fn default_backend() -> Box<dyn IoBackend> {
Box::new(RayonBackend)
}