2020-07-09 17:27:24 +00:00
|
|
|
use std::{fmt::Display, str::FromStr};
|
|
|
|
|
2020-08-03 00:42:27 +00:00
|
|
|
#[derive(Debug, PartialEq)]
|
2020-07-09 17:27:24 +00:00
|
|
|
pub(crate) enum FileKind {
|
2021-04-04 12:30:31 +00:00
|
|
|
Text,
|
|
|
|
Binary,
|
2020-07-09 17:27:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Display for FileKind {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
match self {
|
2021-04-04 12:30:31 +00:00
|
|
|
FileKind::Text => write!(f, "text"),
|
|
|
|
FileKind::Binary => write!(f, "binary"),
|
2020-07-09 17:27:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromStr for FileKind {
|
|
|
|
type Err = String;
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
|
|
match s.to_lowercase().as_str() {
|
2021-04-04 12:30:31 +00:00
|
|
|
"text" => Ok(FileKind::Text),
|
|
|
|
"binary" => Ok(FileKind::Binary),
|
2020-07-09 17:27:24 +00:00
|
|
|
_ => Err(format!("unknown kind {}", s)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|