#![deny(missing_docs)]
use std::fmt;
use enum_as_inner::EnumAsInner;
use thiserror::Error;
#[derive(Debug, EnumAsInner, Error)]
#[non_exhaustive]
pub enum ErrorKind {
#[error("{0}")]
Message(&'static str),
#[error("{0}")]
Msg(String),
#[error("{0}")]
Io(#[from] std::io::Error),
#[error("{0}")]
Cafebabe(#[from] cafebabe::ParseError),
}
#[derive(Error, Debug)]
#[non_exhaustive]
pub struct Error {
pub kind: Box<ErrorKind>,
}
impl Error {
pub fn kind(&self) -> &ErrorKind {
&self.kind
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&self.kind, f)
}
}
impl<E> From<E> for Error
where
E: Into<ErrorKind>,
{
fn from(error: E) -> Self {
let kind: ErrorKind = error.into();
Self {
kind: Box::new(kind),
}
}
}
impl From<&'static str> for Error {
fn from(msg: &'static str) -> Self {
ErrorKind::Message(msg).into()
}
}
impl From<String> for Error {
fn from(msg: String) -> Self {
ErrorKind::Msg(msg).into()
}
}
impl From<Error> for String {
fn from(e: Error) -> Self {
e.to_string()
}
}
pub(crate) trait FromError: From<Error> + std::error::Error + Clone {}
impl<E> FromError for E where E: From<Error> + std::error::Error + Clone {}