weakauras_codec_lib_serialize/
error.rs1use core::fmt;
5use std::error;
6
7use core::num::ParseFloatError;
8use weakauras_codec_lua_value::error::TryFromLuaValueError;
9
10#[derive(Clone, Debug, PartialEq, Eq)]
12#[non_exhaustive]
13pub enum DeserializationError {
14 InvalidPrefix,
16 InvalidTag,
18 InvalidEmbeddedTag,
20 InvalidStringReference,
22 InvalidMapReference,
24 InvalidFloatNumber,
26 InvalidMapKeyType,
29 UnexpectedEof,
31 RecursionLimitExceeded,
33}
34
35impl From<ParseFloatError> for DeserializationError {
36 fn from(_value: ParseFloatError) -> Self {
37 Self::InvalidFloatNumber
38 }
39}
40
41impl From<TryFromLuaValueError> for DeserializationError {
42 fn from(_value: TryFromLuaValueError) -> Self {
43 Self::InvalidMapKeyType
44 }
45}
46
47impl fmt::Display for DeserializationError {
48 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
49 match self {
50 Self::InvalidPrefix => write!(f, "Invalid prefix"),
51 Self::InvalidTag => write!(f, "Invalid tag"),
52 Self::InvalidEmbeddedTag => write!(f, "Invalid embedded tag"),
53 Self::InvalidStringReference => write!(f, "Invalid string reference"),
54 Self::InvalidMapReference => write!(f, "Invalid map reference"),
55 Self::InvalidFloatNumber => write!(f, "Failed to parse a floating-point number"),
56 Self::InvalidMapKeyType => write!(f, "Invalid map key type"),
57 Self::UnexpectedEof => write!(f, "Unexpected EOF"),
58 Self::RecursionLimitExceeded => write!(f, "Recursion limit exceeded"),
59 }
60 }
61}
62
63impl error::Error for DeserializationError {}
64
65#[derive(Clone, Debug, PartialEq, Eq)]
67pub enum SerializationError {
68 TooManyUniqueStrings,
70 StringIsTooLarge,
72 MapIsTooLarge,
74 ArrayIsTooLarge,
76 RecursionLimitExceeded,
78}
79
80impl fmt::Display for SerializationError {
81 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
82 match self {
83 Self::TooManyUniqueStrings => write!(f, "Too many unique strings"),
84 Self::StringIsTooLarge => write!(f, "String is too large"),
85 Self::MapIsTooLarge => write!(f, "Map is too large"),
86 Self::ArrayIsTooLarge => write!(f, "Array is too large"),
87 Self::RecursionLimitExceeded => write!(f, "Recursion limit exceeded"),
88 }
89 }
90}
91
92impl error::Error for SerializationError {}