From e10daa1e5b331e4bdd3017d6bafff5172db7a789 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 2 May 2021 22:11:42 +0100 Subject: [PATCH] if_let: Provide a cardboard cutout version for basic struct variants Signed-off-by: Ian Jackson --- base/misc.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/base/misc.rs b/base/misc.rs index 7ee1c6f5..c6bbe061 100644 --- a/base/misc.rs +++ b/base/misc.rs @@ -75,4 +75,12 @@ macro_rules! if_let { _ => { $($otherwise)* }, }; }; + { $($variant:ident)::+ {$binding:ident} = $input:expr; + else $($otherwise:tt)* + } => { + let $binding = match $input { + $($variant)::+ { $binding } => $binding, + _ => { $($otherwise)* }, + }; + }; } -- 2.30.2