1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
use std::fmt; use failure::Error; #[derive(Clone, Debug)] pub struct OutputRef(pub(crate) String); pub struct ErrorWithCauses(pub Error, &'static str); impl ErrorWithCauses { pub fn multi_line(error: Error) -> Self { Self(error, "\n caused by: ") } pub fn single_line(error: Error) -> Self { Self(error, " => caused by: ") } pub fn into_inner(self) -> Error { self.0 } } impl fmt::Display for ErrorWithCauses { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.0)?; for cause in self.0.iter_causes() { write!(f, "{}{}", self.1, cause)?; } Ok(()) } }