28 lines
669 B
Rust
28 lines
669 B
Rust
use std::{fmt::Display, str::FromStr};
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
pub(crate) enum FileKind {
|
|
Text,
|
|
Binary,
|
|
}
|
|
|
|
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"),
|
|
}
|
|
}
|
|
}
|
|
|
|
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),
|
|
_ => Err(format!("unknown kind {}", s)),
|
|
}
|
|
}
|
|
}
|