use std::{fmt, str};
#[derive(Debug)]
#[derive(Copy, Clone)]
#[derive(PartialEq, Eq)]
pub enum Extension
{
ENV,
JSON,
TOML,
YAML,
}
impl str::FromStr for Extension
{
type Err = String;
fn from_str(extension: &str) -> Result<Self, Self::Err>
{
Ok(match extension {
| "" | "local" | "development" | "test" => Self::ENV,
| "json" => Self::JSON,
| "toml" => Self::TOML,
| "yml" | "yaml" => Self::YAML,
| _ => return Err(format!("L'extension de fichier « {extension} » n'est pas valide")),
})
}
}
impl fmt::Display for Extension
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
{
let extension = match self {
| Extension::ENV => "env",
| Extension::JSON => "json",
| Extension::TOML => "toml",
| Extension::YAML => "yml",
};
write!(f, "{}", extension)
}
}