pub mod statistics;
pub mod throttle;
use std::{any::Any, fmt::Debug, sync::Arc};
use foyer_common::error::Result;
use crate::io::device::statistics::Statistics;
pub type PartitionId = u32;
#[cfg(any(target_family = "unix", target_family = "wasm"))]
pub struct RawFile(pub std::os::fd::RawFd);
#[cfg(target_family = "windows")]
pub struct RawFile(pub std::os::windows::io::RawHandle);
unsafe impl Send for RawFile {}
unsafe impl Sync for RawFile {}
pub trait DeviceBuilder: Send + Sync + 'static + Debug {
fn build(self) -> Result<Arc<dyn Device>>;
}
pub trait Partition: Send + Sync + 'static + Debug + Any {
fn id(&self) -> PartitionId;
fn size(&self) -> usize;
fn translate(&self, address: u64) -> (RawFile, u64);
fn statistics(&self) -> &Arc<Statistics>;
}
pub trait Device: Send + Sync + 'static + Debug + Any {
fn capacity(&self) -> usize;
fn allocated(&self) -> usize;
fn free(&self) -> usize {
self.capacity() - self.allocated()
}
fn create_partition(&self, size: usize) -> Result<Arc<dyn Partition>>;
fn partitions(&self) -> usize;
fn partition(&self, id: PartitionId) -> Arc<dyn Partition>;
fn statistics(&self) -> &Arc<Statistics>;
}
pub mod file;
pub mod fs;
pub mod noop;
pub mod combined;
pub mod partial;