2020-05-22 06:51:15 +00:00
|
|
|
use core::fmt;
|
|
|
|
use serde::export::Formatter;
|
|
|
|
use std::error;
|
2020-05-23 08:14:21 +00:00
|
|
|
use std::error::Error;
|
2020-05-22 06:51:15 +00:00
|
|
|
|
|
|
|
/// Simple rust error
|
|
|
|
///
|
|
|
|
/// @author Pierre Hubert
|
|
|
|
|
2020-05-23 07:37:21 +00:00
|
|
|
|
|
|
|
/// Simple result type
|
|
|
|
pub type ResultExecError<E> = Result<E, ExecError>;
|
2020-05-23 08:14:21 +00:00
|
|
|
pub type ResultBoxError<E> = Result<E, Box<dyn Error>>;
|
2020-05-23 07:37:21 +00:00
|
|
|
|
2020-05-22 06:51:15 +00:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct ExecError(pub String);
|
|
|
|
|
|
|
|
impl ExecError {
|
|
|
|
pub fn new(msg: &str) -> ExecError {
|
|
|
|
ExecError(msg.to_string())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn boxed_new(msg: &str) -> Box<ExecError> {
|
|
|
|
Box::new(ExecError(msg.to_string()))
|
|
|
|
}
|
2020-05-23 07:37:21 +00:00
|
|
|
|
|
|
|
pub fn boxed_string(msg: String) -> Box<ExecError> {
|
|
|
|
Box::new(ExecError(msg))
|
|
|
|
}
|
2020-05-22 06:51:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for ExecError {
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
|
|
|
write!(f, "Encountered error: {}", self.0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl error::Error for ExecError {}
|