stak_file/file_system/
void.rs

1use crate::{FileDescriptor, FileError, FileSystem};
2use stak_vm::{Memory, Value};
3
4/// A file system that does nothing and fails every operation.
5#[derive(Debug)]
6pub struct VoidFileSystem {}
7
8impl VoidFileSystem {
9    /// Creates a file system.
10    pub const fn new() -> Self {
11        Self {}
12    }
13}
14
15impl FileSystem for VoidFileSystem {
16    type Path = [u8];
17    type PathBuf = [u8; 0];
18    type Error = FileError;
19
20    fn open(&mut self, _: &Self::Path, _: bool) -> Result<FileDescriptor, Self::Error> {
21        Err(FileError::Open)
22    }
23
24    fn close(&mut self, _: FileDescriptor) -> Result<(), Self::Error> {
25        Err(FileError::Close)
26    }
27
28    fn read(&mut self, _: FileDescriptor) -> Result<Option<u8>, Self::Error> {
29        Err(FileError::Read)
30    }
31
32    fn write(&mut self, _: FileDescriptor, _: u8) -> Result<(), Self::Error> {
33        Err(FileError::Write)
34    }
35
36    fn flush(&mut self, _: FileDescriptor) -> Result<(), Self::Error> {
37        Err(FileError::Flush)
38    }
39
40    fn delete(&mut self, _: &Self::Path) -> Result<(), Self::Error> {
41        Err(FileError::Delete)
42    }
43
44    fn exists(&self, _: &Self::Path) -> Result<bool, Self::Error> {
45        Err(FileError::Exists)
46    }
47
48    fn decode_path(_: &Memory, _: Value) -> Result<Self::PathBuf, Self::Error> {
49        Err(FileError::PathDecode)
50    }
51}
52
53impl Default for VoidFileSystem {
54    fn default() -> Self {
55        Self::new()
56    }
57}