chainerror/booksrc/tutorial6.md
2019-03-04 11:44:15 +01:00

487 B

Downcast the Errors

std::error::Error comes with some helper methods to get to the original object of the &(dyn Error + 'static) returned by .source().

pub fn downcast_ref<T: Error + 'static>(&self) -> Option<&T>
pub fn downcast_mut<T: Error + 'static>(&mut self) -> Option<&mut T>

This is how it looks like, when using those:

{{#include ../examples/tutorial6.rs}}
# #[allow(dead_code)]
# mod chainerror {
{{#includecomment ../src/lib.rs}}
# }