Coverage Report

Created: 2026-10-28 07:08

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/postcard-1.1.3/src/error.rs
Line
Count
Source
1
use core::fmt::{Display, Formatter};
2
use serde::{Deserialize, Serialize};
3
4
/// This is the error type used by Postcard
5
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
6
#[cfg_attr(feature = "use-defmt", derive(defmt::Format))]
7
#[non_exhaustive]
8
pub enum Error {
9
    /// This is a feature that postcard will never implement
10
    WontImplement,
11
    /// This is a feature that postcard intends to support, but does not yet
12
    NotYetImplemented,
13
    /// The serialize buffer is full
14
    SerializeBufferFull,
15
    /// The length of a sequence must be known
16
    SerializeSeqLengthUnknown,
17
    /// Hit the end of buffer, expected more data
18
    DeserializeUnexpectedEnd,
19
    /// Found a varint that didn't terminate. Is the usize too big for this platform?
20
    DeserializeBadVarint,
21
    /// Found a bool that wasn't 0 or 1
22
    DeserializeBadBool,
23
    /// Found an invalid unicode char
24
    DeserializeBadChar,
25
    /// Tried to parse invalid utf-8
26
    DeserializeBadUtf8,
27
    /// Found an Option discriminant that wasn't 0 or 1
28
    DeserializeBadOption,
29
    /// Found an enum discriminant that was > `u32::MAX`
30
    DeserializeBadEnum,
31
    /// The original data was not well encoded
32
    DeserializeBadEncoding,
33
    /// Bad CRC while deserializing
34
    DeserializeBadCrc,
35
    /// Serde Serialization Error
36
    SerdeSerCustom,
37
    /// Serde Deserialization Error
38
    SerdeDeCustom,
39
    /// Error while processing `collect_str` during serialization
40
    CollectStrError,
41
}
42
43
impl Display for Error {
44
0
    fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
45
        use Error::*;
46
0
        write!(
47
0
            f,
48
            "{}",
49
0
            match self {
50
0
                WontImplement => "This is a feature that PostCard will never implement",
51
                NotYetImplemented => {
52
0
                    "This is a feature that Postcard intends to support, but does not yet"
53
                }
54
0
                SerializeBufferFull => "The serialize buffer is full",
55
0
                SerializeSeqLengthUnknown => "The length of a sequence must be known",
56
0
                DeserializeUnexpectedEnd => "Hit the end of buffer, expected more data",
57
                DeserializeBadVarint => {
58
0
                    "Found a varint that didn't terminate. Is the usize too big for this platform?"
59
                }
60
0
                DeserializeBadBool => "Found a bool that wasn't 0 or 1",
61
0
                DeserializeBadChar => "Found an invalid unicode char",
62
0
                DeserializeBadUtf8 => "Tried to parse invalid utf-8",
63
0
                DeserializeBadOption => "Found an Option discriminant that wasn't 0 or 1",
64
0
                DeserializeBadEnum => "Found an enum discriminant that was > u32::max_value()",
65
0
                DeserializeBadEncoding => "The original data was not well encoded",
66
0
                DeserializeBadCrc => "Bad CRC while deserializing",
67
0
                SerdeSerCustom => "Serde Serialization Error",
68
0
                SerdeDeCustom => "Serde Deserialization Error",
69
0
                CollectStrError => "Error while processing `collect_str` during serialization",
70
            }
71
        )
72
0
    }
73
}
74
75
/// This is the Result type used by Postcard.
76
pub type Result<T> = ::core::result::Result<T, Error>;
77
78
impl serde::ser::Error for Error {
79
0
    fn custom<T>(_msg: T) -> Self
80
0
    where
81
0
        T: Display,
82
    {
83
0
        Error::SerdeSerCustom
84
0
    }
Unexecuted instantiation: <postcard::error::Error as serde_core::ser::Error>::custom::<&str>
Unexecuted instantiation: <postcard::error::Error as serde_core::ser::Error>::custom::<_>
85
}
86
87
impl serde::de::Error for Error {
88
0
    fn custom<T>(_msg: T) -> Self
89
0
    where
90
0
        T: Display,
91
    {
92
0
        Error::SerdeDeCustom
93
0
    }
Unexecuted instantiation: <postcard::error::Error as serde_core::de::Error>::custom::<core::fmt::Arguments>
Unexecuted instantiation: <postcard::error::Error as serde_core::de::Error>::custom::<core::fmt::Arguments>
Unexecuted instantiation: <postcard::error::Error as serde_core::de::Error>::custom::<_>
94
}
95
96
impl serde::ser::StdError for Error {}