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