移除无用的errors文件

This commit is contained in:
liyunjia 2024-05-23 21:58:57 +08:00
parent b3ffac651b
commit 0dabb67544

View File

@ -1,36 +0,0 @@
use core::fmt;
use std::error::Error;
#[derive(Debug)]
pub struct MessageError(Option<String>);
// 实现Error trait
impl Error for MessageError {
fn cause(&self) -> Option<&dyn Error> {
self.source()
}
}
// 实现Display trait这是Error trait的一部分要求
impl fmt::Display for MessageError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self.0 {
Some(message) => write!(f, "{}", message),
None => write!(f, "")
}
}
}
impl From<String> for MessageError {
fn from(value: String) -> Self {
MessageError(Some(value))
}
}
impl From<&str> for MessageError {
fn from(value: &str) -> Self {
MessageError(Some(value.to_string()))
}
}