use thiserror::Error;
pub type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Error, Debug)]
pub enum Error {
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("Parser error: {0}")]
Parser(String),
#[error("Type error: {0}")]
Type(String),
#[error("Invalid argument: {0}")]
Argument(String),
#[error("Not implemented: {0}")]
NotImplemented(String),
#[error("{0}")]
Other(String),
}
impl Error {
pub fn parser_error(msg: impl Into<String>) -> Self {
Self::Parser(msg.into())
}
pub fn type_error(msg: impl Into<String>) -> Self {
Self::Type(msg.into())
}
pub fn argument_error(msg: impl Into<String>) -> Self {
Self::Argument(msg.into())
}
pub fn not_implemented(feature: impl Into<String>) -> Self {
Self::NotImplemented(feature.into())
}
}
impl From<&str> for Error {
fn from(s: &str) -> Self {
Self::Other(s.to_string())
}
}
impl From<String> for Error {
fn from(s: String) -> Self {
Self::Other(s)
}
}