all: split reusable components into workspace crates
This commit is contained in:
parent
2a079ed800
commit
657e7ce2f7
225 changed files with 7422 additions and 17602 deletions
23
utils/src/errorfmt.rs
Normal file
23
utils/src/errorfmt.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
use std::{
|
||||
error::Error,
|
||||
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