#![no_std]
#![deny(missing_docs)]
#[derive(Copy, PartialEq, Eq, Clone, Debug)]
pub enum SeekFrom {
Start(u64),
End(i64),
Current(i64),
}
#[derive(Debug, Clone, PartialEq, Eq, Default, Hash)]
pub struct OpenOptions<Permissions> {
read: bool,
write: bool,
append: bool,
truncate: bool,
create: bool,
create_new: bool,
mode: Permissions,
flags: u32,
}
impl<Permissions: Default> OpenOptions<Permissions> {
pub fn new() -> Self {
OpenOptions::default()
}
pub fn read(&mut self, read: bool) -> &mut Self {
self.read = read;
self
}
pub fn write(&mut self, write: bool) -> &mut Self {
self.write = write;
self
}
pub fn append(&mut self, append: bool) -> &mut Self {
self.append = append;
self
}
pub fn truncate(&mut self, truncate: bool) -> &mut Self {
self.truncate = truncate;
self
}
pub fn create(&mut self, create: bool) -> &mut Self {
self.create = create;
self
}
pub fn create_new(&mut self, create_new: bool) -> &mut Self {
self.create_new = create_new;
self
}
pub fn mode(&mut self, mode: Permissions) -> &mut Self {
self.mode = mode;
self
}
pub fn custom_flags(&mut self, flags: u32) -> &mut Self {
self.flags = flags;
self
}
}
#[derive(Debug, Clone, PartialEq, Eq, Default, Hash)]
pub struct DirOptions<Permissions> {
recursive: bool,
mode: Permissions,
flags: u32,
}
impl<Permissions: Default> DirOptions<Permissions> {
pub fn new() -> Self {
DirOptions::default()
}
pub fn recursive(&mut self, recursive: bool) -> &mut Self {
self.recursive = recursive;
self
}
pub fn mode(&mut self, mode: Permissions) -> &mut Self {
self.mode = mode;
self
}
pub fn custom_flags(&mut self, flags: u32) -> &mut Self {
self.flags = flags;
self
}
}
pub trait Fs {
type Path: ?Sized;
type PathOwned;
type File: File<Error = Self::Error>;
type Dir: Dir<Self::DirEntry, Self::Error>;
type DirEntry: DirEntry<
Path = Self::Path,
Metadata = Self::Metadata,
Error = Self::Error,
>;
type Metadata;
type Permissions;
type Error;
fn open(
&self,
path: &Self::Path,
options: &OpenOptions<Self::Permissions>,
) -> Result<Self::File, Self::Error>;
fn remove_file(&mut self, path: &Self::Path) -> Result<(), Self::Error>;
fn metadata(
&self,
path: &Self::Path,
) -> Result<Self::Metadata, Self::Error>;
fn symlink_metadata(
&self,
path: &Self::Path,
) -> Result<Self::Metadata, Self::Error>;
fn rename(
&mut self,
from: &Self::Path,
to: &Self::Path,
) -> Result<(), Self::Error>;
fn copy(
&mut self,
from: &Self::Path,
to: &Self::Path,
) -> Result<u64, Self::Error>;
fn hard_link(
&mut self,
src: &Self::Path,
dst: &Self::Path,
) -> Result<(), Self::Error>;
fn symlink(
&mut self,
src: &Self::Path,
dst: &Self::Path,
) -> Result<(), Self::Error>;
fn read_link(
&self,
path: &Self::Path,
) -> Result<Self::PathOwned, Self::Error>;
fn canonicalize(
&self,
path: &Self::Path,
) -> Result<Self::PathOwned, Self::Error>;
fn create_dir(
&mut self,
path: &Self::Path,
options: &DirOptions<Self::Permissions>,
) -> Result<(), Self::Error>;
fn remove_dir(&mut self, path: &Self::Path) -> Result<(), Self::Error>;
fn remove_dir_all(&mut self, path: &Self::Path) -> Result<(), Self::Error>;
fn read_dir(&self, path: &Self::Path) -> Result<Self::Dir, Self::Error>;
fn set_permissions(
&mut self,
path: &Self::Path,
perm: Self::Permissions,
) -> Result<(), Self::Error>;
}
pub trait File {
type Error;
fn read(&self, buf: &mut [u8]) -> Result<usize, Self::Error>;
fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error>;
fn flush(&mut self) -> Result<(), Self::Error>;
fn seek(&mut self, pos: SeekFrom) -> Result<u64, Self::Error>;
}
pub trait Dir<T: DirEntry, E>: Iterator<Item = Result<T, E>> {}
pub trait DirEntry {
type Path: ?Sized;
type PathOwned;
type Metadata;
type FileType;
type Error;
fn path(&self) -> Self::PathOwned;
fn metadata(&self) -> Result<Self::Metadata, Self::Error>;
fn file_type(&self) -> Result<Self::FileType, Self::Error>;
fn file_name(&self) -> &Self::Path;
}