1mod error;
2#[cfg(feature = "libc")]
3mod libc;
4mod memory;
5#[cfg(feature = "std")]
6mod os;
7mod utility;
8mod void;
9
10pub use self::error::FileError;
11use core::error::Error;
12#[cfg(feature = "libc")]
13pub use libc::LibcFileSystem;
14pub use memory::MemoryFileSystem;
15#[cfg(feature = "std")]
16pub use os::OsFileSystem;
17use stak_vm::{Memory, Value};
18pub use void::VoidFileSystem;
19
20pub type FileDescriptor = usize;
22
23pub trait FileSystem {
25 type Path: ?Sized;
27
28 type PathBuf: AsRef<Self::Path>;
30
31 type Error: Error;
33
34 fn open(&mut self, path: &Self::Path, output: bool) -> Result<FileDescriptor, Self::Error>;
36
37 fn close(&mut self, descriptor: FileDescriptor) -> Result<(), Self::Error>;
39
40 fn read(&mut self, descriptor: FileDescriptor) -> Result<Option<u8>, Self::Error>;
42
43 fn write(&mut self, descriptor: FileDescriptor, byte: u8) -> Result<(), Self::Error>;
45
46 fn flush(&mut self, descriptor: FileDescriptor) -> Result<(), Self::Error>;
48
49 fn delete(&mut self, path: &Self::Path) -> Result<(), Self::Error>;
51
52 fn exists(&self, path: &Self::Path) -> Result<bool, Self::Error>;
54
55 fn decode_path(memory: &Memory, list: Value) -> Result<Self::PathBuf, Self::Error>;
57}