use serde_derive::{Deserialize, Serialize};
use std::fmt;
#[derive(Copy, Clone, Debug, Deserialize, Serialize)]
crate enum ErrCode {
Env,
Io,
Parse,
Protocol,
Unknown,
}
impl fmt::Display for ErrCode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{}",
match self {
Self::Env => "env",
Self::Io => "io",
Self::Parse => "parse",
Self::Protocol => "protocol",
Self::Unknown => "unknown",
}
)
}
}
impl Into<&str> for ErrCode {
#[must_use]
fn into(self) -> &'static str {
match self {
Self::Env => "env",
Self::Io => "io",
Self::Parse => "parse",
Self::Protocol => "protocol",
Self::Unknown => "unknown",
}
}
}
impl Into<String> for ErrCode {
#[must_use]
fn into(self) -> String {
let tmp: &str = self.into();
tmp.to_string()
}
}
impl From<&str> for ErrCode {
#[must_use]
fn from(text: &str) -> Self {
match text {
"env" => Self::Env,
"io" => Self::Io,
"parse" => Self::Parse,
"protocol" => Self::Protocol,
_ => Self::Unknown,
}
}
}