[pbs-devel] [PATCH proxmox] simplify const_regex macro

Wolfgang Bumiller w.bumiller at proxmox.com
Tue May 4 14:50:56 CEST 2021


The :vis macro matcher has been stable for a long time now.
Let's use it, and replace the recursion with a plus pattern.

Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
---
 proxmox/src/api/const_regex.rs | 24 ++++++------------------
 1 file changed, 6 insertions(+), 18 deletions(-)

diff --git a/proxmox/src/api/const_regex.rs b/proxmox/src/api/const_regex.rs
index 68a4c0a..f3f16b6 100644
--- a/proxmox/src/api/const_regex.rs
+++ b/proxmox/src/api/const_regex.rs
@@ -39,21 +39,11 @@ impl std::ops::Deref for ConstRegexPattern {
 /// ```
 #[macro_export]
 macro_rules! const_regex {
-    () =>   {};
-    ($(#[$attr:meta])* pub ($($vis:tt)+) $name:ident = $regex:expr; $($rest:tt)*) =>  {
-        $crate::const_regex! { (pub ($($vis)+)) $(#[$attr])* $name = $regex; $($rest)* }
-    };
-    ($(#[$attr:meta])* pub $name:ident = $regex:expr; $($rest:tt)*) =>  {
-        $crate::const_regex! { (pub) $(#[$attr])* $name = $regex; $($rest)* }
-    };
-    ($(#[$attr:meta])* $name:ident = $regex:expr; $($rest:tt)*) =>  {
-        $crate::const_regex! { () $(#[$attr])* $name = $regex; $($rest)* }
-    };
-    (
-        ($($pub:tt)*) $(#[$attr:meta])* $name:ident = $regex:expr;
-        $($rest:tt)*
-    ) =>  {
-        $(#[$attr])* $($pub)* const $name: $crate::api::const_regex::ConstRegexPattern =
+    ($(
+        $(#[$attr:meta])*
+        $vis:vis $name:ident = $regex:expr;
+    )+) =>  { $(
+        $(#[$attr])* $vis const $name: $crate::api::const_regex::ConstRegexPattern =
             $crate::api::const_regex::ConstRegexPattern {
                 regex_string: $regex,
                 regex_obj: (|| ->   &'static ::regex::Regex {
@@ -63,9 +53,7 @@ macro_rules! const_regex {
                     &SCHEMA
                 })
             };
-
-        $crate::const_regex! { $($rest)* }
-    };
+    )+ };
 }
 
 #[cfg(feature = "test-harness")]
-- 
2.20.1






More information about the pbs-devel mailing list