Files
BasicOIDC/src/utils/err.rs
Pierre Hubert fc6ab00e30
All checks were successful
continuous-integration/drone/push Build is passing
Refactor users management (#7)
* Improve general settings management by admin
2022-11-26 16:06:16 +01:00

35 lines
755 B
Rust

use std::error::Error;
use std::fmt;
use std::fmt::{Display, Formatter};
pub type Res<A = ()> = Result<A, Box<dyn Error>>;
#[derive(Debug, Clone)]
pub struct ExecError(pub String);
impl ExecError {
pub fn new(msg: &str) -> ExecError {
ExecError(msg.to_string())
}
pub fn boxed_new<D: Display>(msg: D) -> Box<ExecError> {
Box::new(ExecError(msg.to_string()))
}
pub fn boxed_string(msg: String) -> Box<ExecError> {
Box::new(ExecError(msg))
}
}
impl Display for ExecError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "Encountered error: {}", self.0)
}
}
impl Error for ExecError {}
pub fn new_error<D: Display>(msg: D) -> Res {
Err(ExecError::boxed_new(msg))
}