use std::fmt::{Display, Formatter};
#[must_use]
#[non_exhaustive]
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
pub enum Reason {
UnknownFileSystem,
UnsupportedOperation,
FileNotFound,
FileAlreadyExists,
FileContentNotUtf8,
InvalidPath,
Other,
}
impl Display for Reason {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let s: &str = match self {
Reason::UnknownFileSystem => "unknown file system",
Reason::UnsupportedOperation => "unsupported operation",
Reason::FileNotFound => "file not found",
Reason::FileAlreadyExists => "file already exists",
Reason::FileContentNotUtf8 => "file content not utf-8",
Reason::InvalidPath => "invalid path",
Reason::Other => "other",
};
f.write_str(s)
}
}
#[cfg(test)]
mod tests {
use crate::Reason;
#[test]
fn display() {
for (reason, expected) in [
(Reason::UnknownFileSystem, "unknown file system"),
(Reason::UnsupportedOperation, "unsupported operation"),
(Reason::FileNotFound, "file not found"),
(Reason::FileAlreadyExists, "file already exists"),
(Reason::FileContentNotUtf8, "file content not utf-8"),
(Reason::InvalidPath, "invalid path"),
(Reason::Other, "other"),
] {
assert_eq!(reason.to_string(), expected);
}
}
}