1use crate::code;
2use std::error;
3use std::fmt::{self, Display, Formatter};
4use std::io::Error;
5
6#[derive(Debug)]
7pub enum UnpackError {
8 InvalidData(Error),
9 TypeMismatch(code::Code, String),
10}
11
12impl Display for UnpackError {
13 fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
14 error::Error::description(self).fmt(f)
15 }
16}
17
18impl error::Error for UnpackError {
19 fn description(&self) -> &str {
20 match *self {
21 UnpackError::InvalidData(..) => "failed to read data",
22 UnpackError::TypeMismatch(..) => "type isn't match with the expected one",
23 }
24 }
25
26 fn cause(&self) -> Option<&error::Error> {
27 match *self {
28 UnpackError::InvalidData(ref err) => Some(err),
29 UnpackError::TypeMismatch(..) => None,
30 }
31 }
32}