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)]
5#[non_exhaustive]
6pub enum Reason {
7    /// The file system could not be resolved for the path.
8    UnknownFileSystem,
9
10    /// The file system does not support the operation.
11    UnsupportedOperation,
12
13    /// The file was not found.
14    FileNotFound,
15
16    /// The file already exists.
17    FileAlreadyExists,
18
19    /// The file content was not properly encoded UTF-8.
20    FileContentNotUTF8,
21
22    /// The path is invalid for the operation.
23    InvalidPath,
24
25    /// Another uncategorized reason.
26    Other,
27}
28
29impl Display for Reason {
30    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
31        let s: &str = match self {
32            Reason::UnknownFileSystem => "unknown file system",
33            Reason::UnsupportedOperation => "unsupported operation",
34            Reason::FileNotFound => "file not found",
35            Reason::FileAlreadyExists => "file already exists",
36            Reason::FileContentNotUTF8 => "file content not utf-8",
37            Reason::InvalidPath => "invalid path",
38            Reason::Other => "other",
39        };
40        f.write_str(s)
41    }
42}