autocommit 2022-01-08 19:02:10 CET
This commit is contained in:
parent
d061a5c313
commit
3336f1ab6a
37 changed files with 243 additions and 136 deletions
21
src/utils/errorfmt.rs
Normal file
21
src/utils/errorfmt.rs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
use std::error::Error;
|
||||
use std::fmt::{Display, Formatter};
|
||||
|
||||
pub struct ErrorFmt<E>(pub E);
|
||||
|
||||
impl<E: Error> Display for ErrorFmt<E> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
let mut e_opt = Some(&self.0 as &dyn Error);
|
||||
let mut first = true;
|
||||
while let Some(e) = e_opt {
|
||||
if first {
|
||||
write!(f, "{}", e)?;
|
||||
first = false;
|
||||
} else {
|
||||
write!(f, ": {}", e)?;
|
||||
}
|
||||
e_opt = e.source();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue