use std::convert::From;
use std::error::Error as ErrorTrait;
use std::ffi::NulError;
use std::fmt::{Display, Formatter, Result as FmtResult};
use std::io::Error as IoError;
#[derive(Debug)]
pub enum Error {
NullCharacter(NulError),
OpeningLibraryError(IoError),
SymbolGettingError(IoError),
NullSymbol,
AddrNotMatchingDll(IoError),
}
impl ErrorTrait for Error {
fn source(&self) -> Option<&(dyn ErrorTrait + 'static)> {
use self::Error::*;
match *self {
NullCharacter(ref val) => Some(val),
OpeningLibraryError(_) | SymbolGettingError(_) | NullSymbol | AddrNotMatchingDll(_) => {
None
}
}
}
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter) -> FmtResult {
use self::Error::*;
match self {
NullCharacter(_) => write!(f, "String had a null character"),
OpeningLibraryError(msg) => write!(f, "Could not open library: {msg}"),
SymbolGettingError(msg) => {
write!(f, "Could not obtain symbol from the library: {msg}")
}
NullSymbol => write!(f, "The symbol is NULL"),
AddrNotMatchingDll(_) => write!(f, "Address does not match any dynamic link library"),
}
}
}
impl From<NulError> for Error {
fn from(val: NulError) -> Error {
Error::NullCharacter(val)
}
}