Skip to main content

file_storage/error/
reason.rs

1use std::fmt::{Display, Formatter};
2
3/// The reason for a path operation error.
4#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
5pub enum Reason {
6    /// The file system could not be resolved for the path.
7    UnknownFileSystem,
8
9    /// The file system does not support the operation.
10    UnsupportedOperation,
11
12    /// The file was not found.
13    FileNotFound,
14
15    /// The file already exists.
16    FileAlreadyExists,
17
18    /// The file content was not properly encoded UTF-8.
19    FileContentNotUTF8,
20
21    /// Another uncategorized reason.
22    // todo -- remove this and have Option<Reason> in the error?
23    Other,
24}
25
26impl Display for Reason {
27    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
28        let s: &str = match self {
29            Reason::UnknownFileSystem => "unknown file system",
30            Reason::UnsupportedOperation => "unsupported operation",
31            Reason::FileNotFound => "file not found",
32            Reason::FileAlreadyExists => "file already exists",
33            Reason::FileContentNotUTF8 => "file content not utf-8",
34            Reason::Other => "other",
35        };
36        write!(f, "{}", s)
37    }
38}