#![deny(clippy::dbg_macro)]
pub use error_fatality_proc_macro::{Fatality, Split};
pub trait Fatality: std::error::Error + std::fmt::Debug {
fn is_fatal(&self) -> bool;
}
pub trait Split: std::error::Error + std::fmt::Debug {
type Fatal: std::error::Error + Send + Sync + 'static;
type Jfyi: std::error::Error + Send + Sync + 'static;
fn split(self) -> std::result::Result<Self::Jfyi, Self::Fatal>;
}
pub trait Nested<T, E: Split>
where
Self: Sized,
{
fn into_nested(
self,
) -> std::result::Result<
std::result::Result<T, <E as Split>::Jfyi>,
<E as Split>::Fatal,
>;
}
impl<T, E: Split> Nested<T, E> for std::result::Result<T, E> {
fn into_nested(
self,
) -> std::result::Result<
std::result::Result<T, <E as Split>::Jfyi>,
<E as Split>::Fatal,
> {
match self {
Ok(t) => Ok(Ok(t)),
Err(e) => match e.split() {
Ok(jfyi) => Ok(Err(jfyi)),
Err(fatal) => Err(fatal),
},
}
}
}
#[cfg(test)]
mod test;