28 lines
658 B
Rust
28 lines
658 B
Rust
use std::{fmt::Display, str::FromStr};
|
|
|
|
#[derive(Debug)]
|
|
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)),
|
|
}
|
|
}
|
|
}
|