1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-01-10 04:32:28 +00:00
comunicapiv3/src/data/error.rs

28 lines
566 B
Rust
Raw Normal View History

2020-05-22 06:51:15 +00:00
use core::fmt;
use serde::export::Formatter;
use std::error;
/// Simple rust error
///
/// @author Pierre Hubert
#[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()))
}
}
impl fmt::Display for ExecError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "Encountered error: {}", self.0)
}
}
impl error::Error for ExecError {}