1use std::error::Error as ErrorTrait;
2use std::fmt::{Display, Formatter, Result as FmtResult};
3use std::convert::From;
4use std::ffi::NulError;
5use std::io::Error as IoError;
6
7#[derive(Debug)]
9pub enum Error {
10 NullCharacter(NulError),
13 OpeningLibraryError(IoError),
15 SymbolGettingError(IoError),
17 NullSymbol,
19 AddrNotMatchingDll(IoError)
21}
22
23impl ErrorTrait for Error {
24 fn description(&self) -> &str {
25 use self::Error::*;
26 match self {
27 &NullCharacter(_) => "String had a null character",
28 &OpeningLibraryError(_) => "Could not open library",
29 &SymbolGettingError(_) => "Could not obtain symbol from the library",
30 &NullSymbol => "The symbol is NULL",
31 &AddrNotMatchingDll(_) => "Address does not match any dynamic link library"
32 }
33 }
34
35 fn cause(&self) -> Option<&ErrorTrait> {
36 use self::Error::*;
37 match self {
38 &NullCharacter(ref val) => Some(val),
39 &OpeningLibraryError(_) | &SymbolGettingError(_) | &NullSymbol | &AddrNotMatchingDll(_)=> {
40 None
41 }
42 }
43 }
44}
45
46impl Display for Error {
47 fn fmt(&self, f: &mut Formatter) -> FmtResult {
48 use self::Error::*;
49 f.write_str(self.description())?;
50 match self {
51 &OpeningLibraryError(ref msg) => {
52 f.write_str(": ")?;
53 msg.fmt(f)
54 }
55 &SymbolGettingError(ref msg) => {
56 f.write_str(": ")?;
57 msg.fmt(f)
58 }
59 &NullSymbol | &NullCharacter(_) | &AddrNotMatchingDll(_)=> Ok(()),
60 }
61 }
62}
63
64impl From<NulError> for Error {
65 fn from(val: NulError) -> Error {
66 Error::NullCharacter(val)
67 }
68}