面试题答案
一键面试use std::fmt;
#[derive(Debug)]
struct MyError {
message: String,
}
impl fmt::Display for MyError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.message)
}
}
impl std::error::Error for MyError {}
impl MyError {
fn new(message: &str) -> Self {
MyError {
message: message.to_string(),
}
}
}