datatrash/src/file_kind.rs

28 lines
669 B
Rust
Raw Normal View History

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 {
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 {
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() {
"text" => Ok(FileKind::Text),
"binary" => Ok(FileKind::Binary),
2020-07-09 17:27:24 +00:00
_ => Err(format!("unknown kind {}", s)),
}
}
}