mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-18 00:01:24 +01:00
replace our DisplayWithSources with wee-woo
It's the same thing except with a nice extension trait.
This commit is contained in:
parent
d6475eee6d
commit
41c6fc8029
4 changed files with 11 additions and 36 deletions
30
src/error.rs
30
src/error.rs
|
|
@ -1,39 +1,11 @@
|
|||
//! Error handling facilities
|
||||
|
||||
use std::{fmt, iter, path::PathBuf};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::config::ListenConfig;
|
||||
|
||||
/// Formats an [`Error`][0] and its [`source`][1]s with a separator
|
||||
///
|
||||
/// [0]: std::error::Error
|
||||
/// [1]: std::error::Error::source
|
||||
pub(crate) struct DisplayWithSources<'a> {
|
||||
/// The error (and its sources) to write
|
||||
pub(crate) error: &'a dyn std::error::Error,
|
||||
|
||||
/// Separator to write between the original error and subsequent sources
|
||||
pub(crate) infix: &'static str,
|
||||
}
|
||||
|
||||
impl fmt::Display for DisplayWithSources<'_> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", self.error)?;
|
||||
|
||||
let mut source = self.error.source();
|
||||
|
||||
source
|
||||
.into_iter()
|
||||
.chain(iter::from_fn(|| {
|
||||
source = source.and_then(std::error::Error::source);
|
||||
source
|
||||
}))
|
||||
.try_for_each(|source| write!(f, "{}{source}", self.infix))
|
||||
}
|
||||
}
|
||||
|
||||
/// Top-level errors
|
||||
// Missing docs are allowed here since that kind of information should be
|
||||
// encoded in the error messages themselves anyway.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue