anystack 0.6.0-alpha.3

Flexible and comprehensive error handling.
Documentation
use core::{error::Error, fmt, ptr};

use crate::Report;

#[repr(transparent)]
pub(crate) struct ReportError<C: ?Sized>(Report<C>);

impl<C: ?Sized> ReportError<C> {
    pub(crate) const fn new(report: Report<C>) -> Self {
        Self(report)
    }

    pub(crate) const fn from_ref(report: &Report<C>) -> &Self {
        // SAFETY: `ReportError` is a `repr(transparent)` wrapper around `Report`.
        unsafe { &*ptr::from_ref(report).cast() }
    }
}

impl<C: ?Sized> fmt::Debug for ReportError<C> {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        fmt::Debug::fmt(&self.0, f)
    }
}

impl<C: ?Sized> fmt::Display for ReportError<C> {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        fmt::Display::fmt(&self.0, f)
    }
}

impl<C: ?Sized> Error for ReportError<C> {}