musli/context/
error_marker.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use core::fmt;

/// Indicates that an error occurred during encoding. This is a placeholder
/// error that can be used by context implementations and is a ZST.
///
/// Error details are expected to be reported to the corresponding [`Context`].
///
/// [`Context`]: crate::Context
#[derive(Debug)]
#[non_exhaustive]
pub struct ErrorMarker;

impl fmt::Display for ErrorMarker {
    #[inline]
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "Error during encoding or decoding (see context)")
    }
}

impl core::error::Error for ErrorMarker {}

#[cfg(test)]
impl crate::context::ContextError for ErrorMarker {
    #[inline]
    fn custom<T>(_: T) -> Self
    where
        T: 'static + Send + Sync + fmt::Display + fmt::Debug,
    {
        ErrorMarker
    }

    #[inline]
    fn message<T>(_: T) -> Self
    where
        T: fmt::Display,
    {
        ErrorMarker
    }
}