mod memory;
#[cfg(feature = "std")]
mod disk;
#[cfg(feature = "std")]
pub use disk::*;
#[cfg(feature = "std")]
pub trait BackedFileError: std::error::Error {
fn is_eof(&self) -> bool;
}
#[cfg(feature = "std")]
impl BackedFileError for std::io::Error {
#[inline]
fn is_eof(&self) -> bool {
self.kind() == std::io::ErrorKind::UnexpectedEof
}
}
impl BackedFileError for core::convert::Infallible {
#[inline]
fn is_eof(&self) -> bool {
false
}
}
#[cfg(not(feature = "std"))]
pub trait BackedFileError: core::fmt::Debug + core::fmt::Display {
fn is_eof(&self) -> bool;
}
pub trait BackedFile {
type Options;
type Error: BackedFileError;
#[cfg(feature = "std")]
fn open<P: AsRef<std::path::Path>>(
path: P,
opts: Self::Options,
) -> Result<(bool, Self), Self::Error>
where
Self: Sized;
#[cfg(not(feature = "std"))]
fn open(opts: Self::Options) -> Result<(bool, Self), Self::Error>
where
Self: Sized;
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Self::Error>;
fn write_all(&mut self, data: &[u8]) -> Result<(), Self::Error>;
fn flush(&mut self) -> Result<(), Self::Error>;
fn sync_all(&self) -> Result<(), Self::Error>;
fn truncate(&mut self, len: u64) -> Result<(), Self::Error>;
fn size(&self) -> Result<u64, Self::Error>;
}