1use std::error::Error as StdError;
6use std::fmt;
7
8#[derive(Debug)]
10pub struct Error(Box<ErrorKind>);
11
12#[must_use]
14pub fn new(kind: ErrorKind) -> Error {
15 Error(Box::new(kind))
16}
17
18#[derive(Debug)]
20pub enum ErrorKind {
21 #[cfg(feature = "messagepack")]
23 MessagePackSerialization(rmp_serde::encode::Error),
24 #[cfg(feature = "messagepack")]
26 MessagePackDeserialization(rmp_serde::decode::Error),
27}
28
29impl StdError for Error {}
30
31impl fmt::Display for Error {
32 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
33 let errstr = match self.0.as_ref() {
34 #[cfg(feature = "messagepack")]
35 ErrorKind::MessagePackSerialization(e) => e.to_string(),
36 #[cfg(feature = "messagepack")]
37 ErrorKind::MessagePackDeserialization(e) => e.to_string(),
38 };
39 f.write_str(&errstr)
40 }
41}