tools.rs: document try_block macro

This commit is contained in:
Dietmar Maurer 2019-02-15 11:20:45 +01:00
parent f0dbba8cbe
commit e80503d2a6

View File

@ -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)* })() }}