summaryrefslogtreecommitdiffstats
path: root/openpgp/src/macros.rs
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@pep.foundation>2019-03-26 10:20:24 +0100
committerNeal H. Walfield <neal@pep.foundation>2019-03-26 11:29:53 +0100
commit16df977e1820e1004376903b6f6196d5969bce4e (patch)
tree3585292db6eb187f4e81d2a8c575052053d81b6e /openpgp/src/macros.rs
parent5b9770d6769a30fd1ecd7cb806c9997bdd3b6d7c (diff)
openpgp: Move destructures_to macro to macros.rs
Diffstat (limited to 'openpgp/src/macros.rs')
-rw-r--r--openpgp/src/macros.rs20
1 files changed, 20 insertions, 0 deletions
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 {