use core::error::Error;
use core::fmt;
use core::str;
use crate::Allocator;
pub trait Context: Copy {
type Error;
type Mark;
type Allocator: Allocator;
fn clear(self);
fn advance(self, n: usize);
fn mark(self) -> Self::Mark;
fn restore(self, mark: &Self::Mark);
fn alloc(self) -> Self::Allocator;
#[inline]
fn map<E>(self) -> impl FnOnce(E) -> Self::Error
where
E: 'static + Send + Sync + Error,
{
move |error| self.custom(error)
}
fn custom<E>(self, error: E) -> Self::Error
where
E: 'static + Send + Sync + Error;
fn message<M>(self, message: M) -> Self::Error
where
M: fmt::Display;
#[inline]
fn message_at<M>(self, mark: &Self::Mark, message: M) -> Self::Error
where
M: fmt::Display,
{
_ = mark;
self.message(message)
}
#[inline]
fn custom_at<E>(self, mark: &Self::Mark, message: E) -> Self::Error
where
E: 'static + Send + Sync + Error,
{
_ = mark;
self.custom(message)
}
#[inline]
fn enter_struct(self, type_name: &'static str) {
_ = type_name;
}
#[inline]
fn leave_struct(self) {}
#[inline]
fn enter_enum(self, type_name: &'static str) {
_ = type_name;
}
#[inline]
fn leave_enum(self) {}
#[inline]
fn enter_named_field<F>(self, type_name: &'static str, field: F)
where
F: fmt::Display,
{
_ = type_name;
_ = field;
}
#[inline]
fn enter_unnamed_field<F>(self, index: u32, name: F)
where
F: fmt::Display,
{
_ = index;
_ = name;
}
#[inline]
fn leave_field(self) {}
#[inline]
fn enter_variant<V>(self, type_name: &'static str, tag: V)
where
V: fmt::Display,
{
_ = type_name;
_ = tag;
}
#[inline]
fn leave_variant(self) {}
#[inline]
fn enter_map_key<K>(self, field: K)
where
K: fmt::Display,
{
_ = field;
}
#[inline]
fn leave_map_key(self) {}
#[inline]
fn enter_sequence_index(self, index: usize) {
_ = index;
}
#[inline]
fn leave_sequence_index(self) {}
}