try_block/lib.rs
1/// Macro to make your error-handling blocks (appear) lambda-less
2///
3/// #### Before:
4/// ```
5/// let result: Result<T, E> = || {
6/// let a = do_one(x)?;
7/// let b = do_two(a)?;
8/// Ok(b)
9/// }();
10/// ```
11///
12/// #### After:
13/// ```
14/// let result: Result<T, E> = try_block! {
15/// let a = do_one(x)?;
16/// let b = do_two(a)?;
17/// Ok(b)
18/// };
19/// ```
20
21#[macro_export]
22macro_rules! try_block {
23 { $($token:tt)* } => {{
24 let l = || {
25 $($token)*
26 };
27 l()
28 }}
29}
30