Created
November 23, 2023 07:17
-
-
Save jxqu3/eb2631ffb832626701cf3f369e4e8ac2 to your computer and use it in GitHub Desktop.
Rust macro to use match as nested ifs, like empty switches in Go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #[macro_export] | |
| // This is a macro to use a match with boolean conditions, like a empty switch in Go. | |
| // Made by github.com/Esper89 in the Rust discord! | |
| macro_rules! cond { | |
| ($($cond:expr => $value:expr),* $(, _ => $dft:expr)? $(,)?) => { | |
| match () { | |
| $(() if $cond => $value,)* | |
| () => ($($dft)?), | |
| } | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment