pub enum Error {
Basic(DateTime<Local>, Box<dyn Error>),
Custom(DateTime<Local>, String),
}
Expand description
Variants§
Basic(DateTime<Local>, Box<dyn Error>)
用于包装已经实现Error Trait的结构体或枚举
Custom(DateTime<Local>, String)
用于报告用户自定义的错误信息
Implementations§
Source§impl Error
impl Error
Sourcepub fn time(&self) -> DateTime<Local>
pub fn time(&self) -> DateTime<Local>
获取错误发生的时间
§Example
let time = easy_err::Error::custom("Here is a custom error.").time();
println!("{}", time);
Sourcepub fn basic(err: impl Error + 'static) -> Error
pub fn basic(err: impl Error + 'static) -> Error
产生一个basic变体
§Examples
let file = std::fs::File::open("An obvious mistake.").or_else(|err|{Err(easy_err::Error::basic(err))});
match file {
Ok(_) => println!("Ok!"),
Err(err) => {err.report();}
}
Sourcepub fn report(&self) -> &Self
pub fn report(&self) -> &Self
在标准错误流中输出一条报告信息
§Examples
let custom_err = easy_err::Error::custom("Here is a error.");
custom_err.report();
// output:
// error:
// time: <ErrorTime>
// msg: 'Here is a error.'
Trait Implementations§
Source§impl Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Auto Trait Implementations§
impl Freeze for Error
impl !RefUnwindSafe for Error
impl !Send for Error
impl !Sync for Error
impl Unpin for Error
impl !UnwindSafe for Error
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more