From 0dabb675447a4fe0a8459b9e45a188d0995268ce Mon Sep 17 00:00:00 2001 From: liyunjia Date: Thu, 23 May 2024 21:58:57 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E6=97=A0=E7=94=A8=E7=9A=84er?= =?UTF-8?q?rors=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/src/errors.rs | 36 ------------------------------------ 1 file changed, 36 deletions(-) delete mode 100644 library/src/errors.rs diff --git a/library/src/errors.rs b/library/src/errors.rs deleted file mode 100644 index c1e343c..0000000 --- a/library/src/errors.rs +++ /dev/null @@ -1,36 +0,0 @@ -use core::fmt; -use std::error::Error; - -#[derive(Debug)] -pub struct MessageError(Option); - -// 实现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 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())) - } -} \ No newline at end of file