diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-07-29 17:46:57 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-29 17:46:57 +0200 |
| commit | f34ba3dcda182d9b9c14cc94fdb48810bf18bef0 (patch) | |
| tree | 667a7aba2f26996c7ada8ce85952c384a1dbd5a1 /src/macros.rs | |
| parent | e7ffdde43d09f60238590723c2829554806e23d5 (diff) | |
| parent | 9672d4320052d08b67d497febed4a0ad78bf9252 (diff) | |
Merge pull request #7 from typst/parser-update
Parser update
Diffstat (limited to 'src/macros.rs')
| -rw-r--r-- | src/macros.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/macros.rs b/src/macros.rs new file mode 100644 index 00000000..8ba32650 --- /dev/null +++ b/src/macros.rs @@ -0,0 +1,25 @@ +#![allow(unused)] + +/// Unwrap the result if it is `Ok(T)` or evaluate `$or` if it is `Err(_)`. +/// This fits use cases the `?`-operator does not cover, like: +/// ``` +/// try_or!(result, continue); +/// ``` +macro_rules! try_or { + ($result:expr, $or:expr $(,)?) => { + match $result { + Ok(v) => v, + Err(_) => { $or } + } + }; +} + +/// Unwrap the option if it is `Some(T)` or evaluate `$or` if it is `None`. +macro_rules! try_opt_or { + ($option:expr, $or:expr $(,)?) => { + match $option { + Some(v) => v, + None => { $or } + } + }; +} |
