derail 0.3.0

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

use alloc::{boxed::Box, rc::Rc, sync::Arc};
use core::ops::ControlFlow;

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

impl<T> Error for Box<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 Rc<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 Arc<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()
    }
}