derail 0.3.0

An alternative to `core::error::Error`.
Documentation
//! `impl`s for [`Error`] that require [`core`].

use core::{convert::Infallible, ops::ControlFlow};

use crate::{Error, VisitContext, Visitor};

impl<T> Error for &T
where
    T: Error + ?Sized,
{
    type Details = T::Details;

    fn accept(
        &self,
        visitor: &mut dyn Visitor<Details = Self::Details>,
        ctx: VisitContext<'_, Self::Details>,
    ) -> ControlFlow<()> {
        (**self).accept(visitor, ctx)
    }

    fn details(&self) -> Self::Details {
        (**self).details()
    }
}

impl<T> Error for &mut T
where
    T: Error + ?Sized,
{
    type Details = T::Details;

    fn accept(
        &self,
        visitor: &mut dyn Visitor<Details = Self::Details>,
        ctx: VisitContext<'_, Self::Details>,
    ) -> ControlFlow<()> {
        (**self).accept(visitor, ctx)
    }

    fn details(&self) -> Self::Details {
        (**self).details()
    }
}

impl Error for Infallible {
    type Details = Self;

    fn accept(
        &self,
        _visitor: &mut dyn Visitor<Details = Self::Details>,
        _ctx: VisitContext<'_, Self::Details>,
    ) -> ControlFlow<()> {
        match *self {}
    }

    fn details(&self) -> Self::Details {
        match *self {}
    }
}