use std::{fmt, io};
pub type Result<T> = core::result::Result<T, Error>;
#[derive(Debug)]
#[non_exhaustive]
pub enum Error {
Io(io::ErrorKind),
Parse(String),
Version(semver::Error),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Io(kind) => write!(f, "I/O operation failed: {}", kind),
Error::Parse(s) => write!(f, "parse error: {}", s),
Error::Version(err) => write!(f, "version error: {}", err),
}
}
}
impl From<io::Error> for Error {
fn from(err: io::Error) -> Self {
Error::Io(err.kind())
}
}
impl From<semver::Error> for Error {
fn from(err: semver::Error) -> Self {
Error::Version(err)
}
}
impl From<std::num::ParseIntError> for Error {
fn from(err: std::num::ParseIntError) -> Self {
Error::Parse(err.to_string())
}
}
impl From<toml::de::Error> for Error {
fn from(err: toml::de::Error) -> Self {
Error::Parse(err.to_string())
}
}
impl std::error::Error for Error {}