From 903644247413a1e2cea20c69730aa3d10b1eeb3b Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 16 May 2021 23:24:52 +0100 Subject: [PATCH] if_let: Provide a way to get at the error 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 faa47bc4..66c98fff 100644 --- a/base/misc.rs +++ b/base/misc.rs @@ -67,6 +67,14 @@ pub fn space_rect_attrs(table_size: PosC) -> SvgAttrs { #[macro_export] macro_rules! if_let { + { $($variant:ident)::+ ($binding:pat) = $input:expr; + match $($otherwise:tt)* + } => { + let $binding = match $input { + $($variant)::+ (y) => y, + $($otherwise)*, + }; + }; { $($variant:ident)::+ ($binding:pat) = $input:expr; else $($otherwise:tt)* } => { -- 2.30.2