-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherror.rs
More file actions
45 lines (39 loc) · 1.22 KB
/
Copy patherror.rs
File metadata and controls
45 lines (39 loc) · 1.22 KB
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
//! Unified error type for MessagePack encode/decode operations.
use std::error::Error as StdError;
use std::fmt;
/// Error returned by [`crate::message_pack_format::MessagePackCodec`]
/// implementations and by the `dto`-level free functions in
/// [`crate::message_pack_format`].
#[derive(Debug)]
pub enum Error {
/// MessagePack encoding failed.
Encode(rmp_serde::encode::Error),
/// MessagePack decoding failed.
Decode(rmp_serde::decode::Error),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Encode(e) => write!(f, "MessagePack encode failed: {e}"),
Error::Decode(e) => write!(f, "MessagePack decode failed: {e}"),
}
}
}
impl StdError for Error {
fn source(&self) -> Option<&(dyn StdError + 'static)> {
match self {
Error::Encode(e) => Some(e),
Error::Decode(e) => Some(e),
}
}
}
impl From<rmp_serde::encode::Error> for Error {
fn from(value: rmp_serde::encode::Error) -> Self {
Error::Encode(value)
}
}
impl From<rmp_serde::decode::Error> for Error {
fn from(value: rmp_serde::decode::Error) -> Self {
Error::Decode(value)
}
}