use std::error;
use std::fmt;
use std::result;
pub type Result<T> = result::Result<T, Box<dyn error::Error>>;
#[derive(Debug)]
pub struct SetupError {
details: String,
}
impl SetupError {
pub fn new(msg: &str) -> Self {
Self {
details: msg.to_string(),
}
}
}
impl fmt::Display for SetupError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.details)
}
}
impl error::Error for SetupError {
fn description(&self) -> &str {
&self.details
}
}
#[derive(Debug)]
pub struct ExecutionError {
details: String,
}
impl ExecutionError {
pub fn new(msg: &str) -> Self {
Self {
details: msg.to_string(),
}
}
}
impl fmt::Display for ExecutionError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.details)
}
}
impl error::Error for ExecutionError {
fn description(&self) -> &str {
&self.details
}
}
#[cfg(test)]
mod tests_error {
use super::*;
#[test]
fn test_setup_error() {
assert_eq!(
"uh oh stinky something went wrong!",
SetupError::new("uh oh stinky something went wrong!")
.to_string()
.as_str(),
);
}
#[test]
fn test_execution_error() {
assert_eq!(
"uh oh stinky something went wrong!",
ExecutionError::new("uh oh stinky something went wrong!")
.to_string()
.as_str(),
);
}
}