use alloc::boxed::Box;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FsError {
Device,
InvalidPath,
NoSuchFile,
}
pub trait BlockDevice {
fn read_blocks(&mut self, lba: u64, buf: &mut [u8]) -> Result<(), FsError>;
fn write_blocks(&mut self, lba: u64, buf: &[u8]) -> Result<(), FsError>;
fn block_size(&self) -> usize;
fn num_blocks(&self) -> u64;
fn flush(&mut self) -> Result<(), FsError>;
}
#[derive(Debug, Clone)]
pub enum AssetError {
Fs(FsError),
}
pub trait AssetRead {
fn read(&mut self, out: &mut [u8]) -> Result<usize, AssetError>;
fn len(&self) -> usize;
fn is_empty(&self) -> bool;
fn seek(&mut self, pos: u64) -> Result<u64, AssetError>;
}
pub trait AssetSource {
fn open<'a>(&'a self, path: &str) -> Result<Box<dyn AssetRead + 'a>, AssetError>;
fn exists(&self, path: &str) -> bool;
fn list(&self, dir: &str) -> Result<AssetIter, AssetError>;
}
pub struct AssetIter;
impl Iterator for AssetIter {
type Item = ();
fn next(&mut self) -> Option<Self::Item> {
None
}
}
pub struct AssetManager<S: AssetSource> {
source: S,
}
impl<S: AssetSource> AssetManager<S> {
pub fn new(source: S) -> Self {
Self { source }
}
pub fn open(&self, path: &str) -> Result<Box<dyn AssetRead + '_>, AssetError> {
self.source.open(path)
}
}