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