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
22#[cfg(test)]
23impl crate::context::ContextError for ErrorMarker {
24    #[inline]
25    fn custom<T>(_: T) -> Self
26    where
27        T: 'static + Send + Sync + fmt::Display + fmt::Debug,
28    {
29        ErrorMarker
30    }
31
32    #[inline]
33    fn message<T>(_: T) -> Self
34    where
35        T: fmt::Display,
36    {
37        ErrorMarker
38    }
39}