From e80503d2a6457d717339537d047134445bf52f55 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Fri, 15 Feb 2019 11:20:45 +0100 Subject: [PATCH] tools.rs: document try_block macro --- src/tools.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/tools.rs b/src/tools.rs index fa970798..05c19e09 100644 --- a/src/tools.rs +++ b/src/tools.rs @@ -27,6 +27,19 @@ pub mod ticket; pub mod borrow; pub mod fs; +/// Macro to write error-handling blocks (like perl eval {}) +/// +/// #### Example: +/// ``` +/// let result = try_block!({ +/// if (some_condition) { +/// bail!("some error"); +/// } +/// Ok(()) +/// }) +/// .map_err(|e| format_err!("my try block returned an error - {}", e)); +/// ``` + #[macro_export] macro_rules! try_block { { $($token:tt)* } => {{ (|| -> Result<_,_> { $($token)* })() }}