From 16df977e1820e1004376903b6f6196d5969bce4e Mon Sep 17 00:00:00 2001 From: "Neal H. Walfield" Date: Tue, 26 Mar 2019 10:20:24 +0100 Subject: openpgp: Move destructures_to macro to macros.rs --- openpgp/src/macros.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'openpgp/src/macros.rs') diff --git a/openpgp/src/macros.rs b/openpgp/src/macros.rs index 20aaa6e5..50be3afa 100644 --- a/openpgp/src/macros.rs +++ b/openpgp/src/macros.rs @@ -1,5 +1,25 @@ use std::cmp; +// Turns an `if let` into an expression so that it is possible to do +// things like: +// +// ```rust,nocompile +// if destructures_to(Foo::Bar(_) = value) +// || destructures_to(Foo::Bam(_) = value) { ... } +// ``` +macro_rules! destructures_to { + ( $error: pat = $expr:expr ) => { + { + let x = $expr; + if let $error = x { + true + } else { + false + } + } + }; +} + macro_rules! trace { ( $TRACE:expr, $fmt:expr, $($pargs:expr),* ) => { if $TRACE { -- cgit v1.2.3