40 lines
706 B
Rust
40 lines
706 B
Rust
|
use std::{error::Error, fmt};
|
||
|
|
||
|
#[derive(Debug)]
|
||
|
pub struct MTTError {
|
||
|
detail: String,
|
||
|
}
|
||
|
|
||
|
impl MTTError {
|
||
|
fn new(detail: &str) -> Self {
|
||
|
Self {
|
||
|
detail: detail.to_string(),
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl fmt::Display for MTTError {
|
||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||
|
write!(f, "{}", self.detail)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl Error for MTTError {}
|
||
|
|
||
|
#[cfg(test)]
|
||
|
mod errors {
|
||
|
use super::*;
|
||
|
|
||
|
#[test]
|
||
|
fn new_error() {
|
||
|
let detail = "new error";
|
||
|
let err = MTTError::new(detail);
|
||
|
assert!(
|
||
|
err.to_string() == detail,
|
||
|
"\n\nGot: {}\nWant: {}\n\n",
|
||
|
err.to_string(),
|
||
|
detail
|
||
|
);
|
||
|
}
|
||
|
}
|