swf_headers/error.rs
1use std::io;
2
3use byteorder;
4use lzma;
5
6/// The error type used by swf-headers.
7///
8/// Anything that could be considered a malformed or corrupt SWF falls into
9/// the broad category of NotSwf, along with everything else that can't be a
10/// SWF file. This may change in the future
11///
12/// Implementations of From for a couple of error types are done to make
13/// using try!() around the place more convenient.
14#[derive(Debug)]
15pub enum Error {
16 /// Any IO error, either from directly reading files or from other libraries.
17 IoError(io::Error),
18 /// All-encompassing variant for anything that can't be a swf file.
19 NotSwf
20}
21
22impl From<io::Error> for Error {
23 fn from(err: io::Error) -> Self {
24 Error::IoError(err)
25 }
26}
27
28impl From<byteorder::Error> for Error {
29 fn from(err: byteorder::Error) -> Self {
30 use byteorder::Error::*;
31 match err {
32 UnexpectedEOF => Error::NotSwf,
33 Io(error) => error.into()
34 }
35 }
36}
37
38impl From<lzma::Error> for Error {
39 fn from(err: lzma::Error) -> Self {
40 use lzma::Error::*;
41 match err {
42 IO(error) => error.into(),
43 ByteOrder(error) => error.into(),
44 _ => Error::NotSwf
45 }
46 }
47}