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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use alloc::string::{String, ToString};
use core::fmt::{Debug, Display, Formatter, Result};
use serde::de::{Error as DeError, StdError};
#[derive(Debug)]
pub enum Error<T> {
Io(T),
Syntax(usize),
Semantic(Option<usize>, String),
RecursionLimitExceeded,
}
impl<T> Error<T> {
#[inline]
pub fn semantic(offset: impl Into<Option<usize>>, msg: impl Into<String>) -> Self {
Self::Semantic(offset.into(), msg.into())
}
}
impl<T> From<T> for Error<T> {
#[inline]
fn from(value: T) -> Self {
Error::Io(value)
}
}
impl<T> From<ciborium_ll::Error<T>> for Error<T> {
#[inline]
fn from(value: ciborium_ll::Error<T>) -> Self {
match value {
ciborium_ll::Error::Io(x) => Self::Io(x),
ciborium_ll::Error::Syntax(x) => Self::Syntax(x),
}
}
}
impl<T: Debug> Display for Error<T> {
#[inline]
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
write!(f, "{:?}", self)
}
}
impl<T: Debug> StdError for Error<T> {}
impl<T: Debug> DeError for Error<T> {
#[inline]
fn custom<U: Display>(msg: U) -> Self {
Self::Semantic(None, msg.to_string())
}
}