1#![deny(unsafe_code)]
5#![deny(trivial_casts, trivial_numeric_casts)]
6#![deny(missing_docs, missing_debug_implementations, missing_copy_implementations)]
7#![deny(unused_extern_crates, unused_import_braces, unused_qualifications)]
8
9extern crate byteorder;
10
11use std::error;
12use std::fmt;
13use std::io;
14
15mod decoder;
16mod encoder;
17#[cfg(test)]
18mod tests;
19
20pub use decoder::Decoder;
21pub use encoder::Encoder;
22
23const HEADER_LEN: u64 = 8+4+4;
24
25pub type Result<T> = ::std::result::Result<T, Error>;
27
28#[derive(Debug)]
30pub enum Error {
31 FormatError(String),
33
34 NotEnoughData,
37
38 IoError(io::Error),
40
41 ImageEnd
43}
44
45
46impl fmt::Display for Error {
47 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
48 match self {
49 &Error::FormatError(ref e) => write!(fmt, "Format error: {}", e),
50 &Error::NotEnoughData => write!(fmt, "Not enough data was provided to the \
51 Decoder to decode the image"),
52 &Error::IoError(ref e) => e.fmt(fmt),
53 &Error::ImageEnd => write!(fmt, "The end of the image has been reached")
54 }
55 }
56}
57
58impl error::Error for Error {
59 fn description (&self) -> &str {
60 match *self {
61 Error::FormatError(..) => &"Format error",
62 Error::NotEnoughData => &"Not enough data",
63 Error::IoError(..) => &"IO error",
64 Error::ImageEnd => &"Image end"
65 }
66 }
67
68 fn cause (&self) -> Option<&error::Error> {
69 match *self {
70 Error::IoError(ref e) => Some(e),
71 _ => None
72 }
73 }
74}
75
76impl From<io::Error> for Error {
77 fn from(err: io::Error) -> Error {
78 Error::IoError(err)
79 }
80}