From eb4681bf653fb0f1b64713c0ecc8cfbf98d5d601 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 12 Oct 2017 19:02:37 +0200 Subject: [PATCH] Add helper for tracing error and exit or unwrap the value --- lib/core/libimagerror/src/trace.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/core/libimagerror/src/trace.rs b/lib/core/libimagerror/src/trace.rs index 3fbc4faf..526654d5 100644 --- a/lib/core/libimagerror/src/trace.rs +++ b/lib/core/libimagerror/src/trace.rs @@ -114,13 +114,17 @@ fn print_trace_dbg(idx: u64, e: &Error) { /// /// and variants pub trait MapErrTrace { + type Output; + fn map_err_trace(self) -> Self; fn map_err_dbg_trace(self) -> Self; fn map_err_trace_exit(self, code: i32) -> Self; + fn map_err_trace_exit_unwrap(self, code: i32) -> Self::Output; fn map_err_trace_maxdepth(self, max: u64) -> Self; } impl MapErrTrace for Result { + type Output = U; /// Simply call `trace_error()` on the Err (if there is one) and return the error. /// @@ -143,6 +147,11 @@ impl MapErrTrace for Result { self.map_err(|e| { trace_error_exit(&e, code) }) } + /// Helper for calling map_err_trace_exit(n).unwrap() in one call + fn map_err_trace_exit_unwrap(self, code: i32) -> Self::Output { + self.map_err_trace_exit(code).unwrap() + } + /// Simply call `trace_error_maxdepth(max)` on the Err (if there is one) and return the error. /// /// This does nothing besides the side effect of printing the error trace to a certain depth