#![deny(missing_docs)]
use std::error;
use std::fmt;
use std::io;
use std::result;
pub mod command;
pub mod target;
pub mod programmer;
pub type Result<T> = result::Result<T, Error>;
#[derive(Debug, PartialEq)]
pub enum ErrorKind {
Connect,
Command(command::CommandError),
Io(io::ErrorKind),
}
#[derive(Debug, PartialEq)]
pub struct Error {
pub kind: ErrorKind,
pub description: String,
}
impl Error {
fn new<T: Into<String>>(kind: ErrorKind, description: T) -> Error {
let description = description.into();
Error { kind, description }
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description)
}
}
impl error::Error for Error {}
impl From<io::Error> for Error {
fn from(io_error: io::Error) -> Error {
Error::new(ErrorKind::Io(io_error.kind()), io_error.to_string())
}
}
impl From<command::CommandError> for Error {
fn from(command_error: command::CommandError) -> Error {
Error::new(ErrorKind::Command(command_error), command_error.to_string())
}
}