Closed shepmaster closed 10 months ago
In #398, we discussed the possibility of adding ResultExt::boxed to allow boxing errors as part of a chain:
ResultExt::boxed
impl<T, E> ResultExt<T, E> for Result<T, E> { fn boxed(self) -> Result<T, Box<dyn snafu::Error + 'static>> where E: snafu::Error + 'static, { self.map_err(|e| Box::new(e) as Box<dyn snafu::Error>) } }
That would allow people to bin multiple concrete errors into one selector:
makes_err_a().boxed().context(ZetaSnafu)?; makes_err_b().boxed().context(ZetaSnafu)?;
Although I'm not in love with throwing away error detail, sometimes this is really the best solution, such as when you are dealing with errors from an associated type:
trait Database { type Error: std::error::Error; fn connect(&self) -> Result<(), Self::Error>; }
In #398, we discussed the possibility of adding
ResultExt::boxed
to allow boxing errors as part of a chain:That would allow people to bin multiple concrete errors into one selector:
Although I'm not in love with throwing away error detail, sometimes this is really the best solution, such as when you are dealing with errors from an associated type: