stak_file/file_system/
error.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
use core::{
    error,
    fmt::{self, Display, Formatter},
};

/// An error.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum FileError {
    /// An open failure.
    Open,
    /// A close failure.
    Close,
    /// A read failure.
    Read,
    /// A write failure.
    Write,
    /// A deletion failure.
    Delete,
    /// A existence check failure.
    Exists,
}

impl error::Error for FileError {}

impl Display for FileError {
    fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
        match self {
            Self::Open => write!(formatter, "cannot open file"),
            Self::Close => write!(formatter, "cannot close file"),
            Self::Read => write!(formatter, "cannot read file"),
            Self::Write => write!(formatter, "cannot write file"),
            Self::Delete => write!(formatter, "cannot delete file"),
            Self::Exists => write!(formatter, "cannot check file existence"),
        }
    }
}