1use std::error::Error;
4
5#[derive(Debug)]
7pub enum IvfError {
8 IoError(std::io::Error),
10 TryFromSliceError(std::array::TryFromSliceError),
12 TryFromIntError(std::num::TryFromIntError),
14 InvalidHeader(String),
16 UnexpectedFileEnding,
18}
19
20impl std::fmt::Display for IvfError {
21 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
22 match self {
23 IvfError::IoError(err) => {
24 write!(f, "{:?}", err.source())
25 }
26 IvfError::TryFromSliceError(err) => {
27 write!(f, "{:?}", err.source())
28 }
29 IvfError::TryFromIntError(err) => {
30 write!(f, "{:?}", err.source())
31 }
32 IvfError::InvalidHeader(message) => {
33 write!(f, "invalid header: {}", message)
34 }
35 IvfError::UnexpectedFileEnding => {
36 write!(f, "unexpected file ending")
37 }
38 }
39 }
40}
41
42impl From<std::io::Error> for IvfError {
43 fn from(err: std::io::Error) -> IvfError {
44 IvfError::IoError(err)
45 }
46}
47
48impl From<std::array::TryFromSliceError> for IvfError {
49 fn from(err: std::array::TryFromSliceError) -> IvfError {
50 IvfError::TryFromSliceError(err)
51 }
52}
53
54impl From<std::num::TryFromIntError> for IvfError {
55 fn from(err: std::num::TryFromIntError) -> IvfError {
56 IvfError::TryFromIntError(err)
57 }
58}
59
60impl std::error::Error for IvfError {
61 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
62 match *self {
63 IvfError::IoError(ref e) => Some(e),
64 IvfError::TryFromSliceError(ref e) => Some(e),
65 IvfError::TryFromIntError(ref e) => Some(e),
66 _ => None,
67 }
68 }
69}