use std::{fmt, io};
#[derive(Debug)]
pub enum Error {
BadProtSpec(String),
IO(std::io::Error),
Pki(String)
}
impl Error {
pub fn bad_protspec(s: impl Into<String>) -> Self {
Self::BadProtSpec(s.into())
}
pub fn pki(s: impl Into<String>) -> Self {
Self::Pki(s.into())
}
}
impl std::error::Error for Error {}
impl From<io::Error> for Error {
fn from(err: io::Error) -> Self {
Self::IO(err)
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::BadProtSpec(s) => {
write!(f, "Unable to parse protocol specifier string; {s}")
}
Self::IO(s) => {
write!(f, "I/O; {s}")
}
Self::Pki(s) => {
write!(f, "PKI; {s}")
}
}
}
}