use core::{fmt, ops::ControlFlow};
use crate::Error;
mod ext;
#[cfg(feature = "alloc")]
mod impls_alloc;
mod impls_core;
pub use ext::VisitorExt;
pub trait Visitor {
type Details;
#[expect(unused_variables)]
fn visit(
&mut self,
visitee: &dyn Error<Details = Self::Details>,
ctx: VisitContext<'_, Self::Details>,
) -> ControlFlow<()> {
ControlFlow::Continue(())
}
fn push(&mut self) -> ControlFlow<()> {
ControlFlow::Continue(())
}
fn pop(&mut self) -> ControlFlow<()> {
ControlFlow::Continue(())
}
}
#[non_exhaustive]
pub struct VisitContext<'a, D> {
pub(crate) next_sibling: Option<&'a dyn Error<Details = D>>,
}
impl<D> VisitContext<'_, D> {
#[must_use]
pub(crate) fn new() -> Self {
Self {
next_sibling: None,
}
}
#[must_use]
pub fn next_sibling(&self) -> Option<&dyn Error<Details = D>> {
self.next_sibling
}
}
impl<D> fmt::Debug for VisitContext<'_, D> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Context")
.field("next_sibling", &self.next_sibling)
.finish_non_exhaustive()
}
}