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    /// The path is invalid for the operation.
22    InvalidPath,
23
24    /// Another uncategorized reason.
25    Other,
26}
27
28impl Display for Reason {
29    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
30        let s: &str = match self {
31            Reason::UnknownFileSystem => "unknown file system",
32            Reason::UnsupportedOperation => "unsupported operation",
33            Reason::FileNotFound => "file not found",
34            Reason::FileAlreadyExists => "file already exists",
35            Reason::FileContentNotUTF8 => "file content not utf-8",
36            Reason::InvalidPath => "invalid path",
37            Reason::Other => "other",
38        };
39        f.write_str(s)
40    }
41}