1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright © 2020 Lexi Frydl
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

mod fail;
pub mod idn;
mod log;
mod path;
mod sync;

/// Runs a block of code and catches `?` operator returns.
///
/// This is just a cleaner version of creating a closure and immediately calling
/// it. It is intended to serve as a replacement for `try { .. }` until it is
/// stable.
#[macro_export]
macro_rules! attempt {
  ($($tokens:tt)+) => {
    (|| { $($tokens)+ })()
  };
}

/// Runs a block of async code and catches `?` operator returns.
///
/// This is just a cleaner version of creating a closure and immediately calling
/// it. It is intended to serve as a replacement for `try { .. }` until it is
/// stable.
#[macro_export]
macro_rules! attempt_async {
  ($($tokens:tt)+) => {
    (|| async { $($tokens)+ })().await
  };
}