use crate::fmt;
use crate::input::{Input, MaybeString, Span};
use super::{
Backtrace, Context, ExpectedLength, ExpectedValid, ExpectedValue, RetryRequirement,
ToRetryRequirement, Value,
};
pub trait Error<'i>:
WithContext<'i>
+ ToRetryRequirement
+ From<ExpectedValue<'i>>
+ From<ExpectedLength<'i>>
+ From<ExpectedValid<'i>>
{
}
impl<'i, T> Error<'i> for T where
T: WithContext<'i>
+ ToRetryRequirement
+ From<ExpectedValue<'i>>
+ From<ExpectedLength<'i>>
+ From<ExpectedValid<'i>>
{
}
pub trait WithContext<'i>: Sized {
const PASSTHROUGH: bool = false;
fn with_input(self, input: impl Input<'i>) -> Self;
fn with_context(self, context: impl Context) -> Self;
}
pub trait Details<'i> {
fn input(&self) -> MaybeString<'i>;
fn expected(&self) -> Option<Value<'_>>;
fn description(&self, w: &mut dyn fmt::Write) -> fmt::Result;
fn backtrace(&self) -> &dyn Backtrace;
}
pub trait External<'i>: Sized {
fn span(&self) -> Option<Span> {
None
}
fn retry_requirement(&self) -> Option<RetryRequirement> {
None
}
fn push_backtrace<E>(self, error: E) -> E
where
E: WithContext<'i>,
{
error
}
}