stak_file/file_system/
void.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use crate::{FileDescriptor, FileError, FileSystem};
use stak_vm::{Memory, Value};

/// A file system that does nothing and fails every operation.
#[derive(Debug)]
pub struct VoidFileSystem {}

impl VoidFileSystem {
    /// Creates a file system.
    pub const fn new() -> Self {
        Self {}
    }
}

impl FileSystem for VoidFileSystem {
    type Path = [u8];
    type PathBuf = [u8; 0];
    type Error = FileError;

    fn open(&mut self, _: &Self::Path, _: bool) -> Result<FileDescriptor, Self::Error> {
        Err(FileError::Open)
    }

    fn close(&mut self, _: FileDescriptor) -> Result<(), Self::Error> {
        Err(FileError::Close)
    }

    fn read(&mut self, _: FileDescriptor) -> Result<u8, Self::Error> {
        Err(FileError::Read)
    }

    fn write(&mut self, _: FileDescriptor, _: u8) -> Result<(), Self::Error> {
        Err(FileError::Write)
    }

    fn delete(&mut self, _: &Self::Path) -> Result<(), Self::Error> {
        Err(FileError::Delete)
    }

    fn exists(&self, _: &Self::Path) -> Result<bool, Self::Error> {
        Err(FileError::Exists)
    }

    fn decode_path(_: &Memory, _: Value) -> Result<Self::PathBuf, Self::Error> {
        Err(FileError::PathDecode)
    }
}

impl Default for VoidFileSystem {
    fn default() -> Self {
        Self::new()
    }
}