musli/context/
error_marker.rs

1use core::fmt;
2
3/// Indicates that an error occurred during encoding. This is a placeholder
4/// error that can be used by context implementations and is a ZST.
5///
6/// Error details are expected to be reported to the corresponding [`Context`].
7///
8/// [`Context`]: crate::Context
9#[derive(Debug)]
10#[non_exhaustive]
11pub struct ErrorMarker;
12
13impl fmt::Display for ErrorMarker {
14    #[inline]
15    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16        write!(f, "Error during encoding or decoding (see context)")
17    }
18}
19
20impl core::error::Error for ErrorMarker {}
21
22impl<A> crate::context::ContextError<A> for ErrorMarker
23where
24    A: crate::Allocator,
25{
26    #[inline]
27    fn custom<T>(_: A, _: T) -> Self
28    where
29        T: 'static + Send + Sync + fmt::Display + fmt::Debug,
30    {
31        ErrorMarker
32    }
33
34    #[inline]
35    fn message<T>(_: A, _: T) -> Self
36    where
37        T: fmt::Display,
38    {
39        ErrorMarker
40    }
41}