all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Dietmar Maurer <dietmar@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox 1/4] proxmox-schema: use const_format to define static strings.
Date: Fri, 15 Mar 2024 12:27:29 +0100	[thread overview]
Message-ID: <20240315112732.368831-1-dietmar@proxmox.com> (raw)

Macro rules are not hygienic, and current rust macro visibility rules
are a nightmare. Using const_format::concatcp!() is a much cleaner
solution.

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
---
 Cargo.toml                      |  1 +
 proxmox-schema/Cargo.toml       |  3 ++-
 proxmox-schema/src/api_types.rs | 12 +++++++-----
 3 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml
index 58d5a67..032ef65 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -55,6 +55,7 @@ base32 = "0.4"
 base64 = "0.13"
 bitflags = "1.2.1"
 bytes = "1.0"
+const_format = "0.2"
 crc32fast = "1"
 crossbeam-channel = "0.5"
 endian_trait = "0.6"
diff --git a/proxmox-schema/Cargo.toml b/proxmox-schema/Cargo.toml
index ae06818..1c150b2 100644
--- a/proxmox-schema/Cargo.toml
+++ b/proxmox-schema/Cargo.toml
@@ -11,6 +11,7 @@ exclude.workspace = true
 
 [dependencies]
 anyhow.workspace = true
+const_format = { workspace = true, optional = true }
 lazy_static.workspace = true
 regex.workspace = true
 serde.workspace = true
@@ -33,7 +34,7 @@ default = []
 
 api-macro = ["dep:proxmox-api-macro"]
 upid-api-impl = [ "dep:libc", "dep:nix" ]
-api-types = []
+api-types = [ "dep:const_format" ]
 
 # Testing only
 test-harness = []
diff --git a/proxmox-schema/src/api_types.rs b/proxmox-schema/src/api_types.rs
index 0cec043..4e10ebb 100644
--- a/proxmox-schema/src/api_types.rs
+++ b/proxmox-schema/src/api_types.rs
@@ -1,10 +1,10 @@
 //! The "basic" api types we generally require along with some of their macros.
+use const_format::concatcp;
 
 use crate::{ApiStringFormat, Schema, StringSchema};
 
 #[rustfmt::skip]
-#[macro_export]
-macro_rules! SAFE_ID_REGEX_STR { () => { r"(?:[A-Za-z0-9_][A-Za-z0-9._\-]*)" }; }
+const SAFE_ID_REGEX_STR: &str = r"(?:[A-Za-z0-9_][A-Za-z0-9._\-]*)";
 
 const_regex! {
     /// Regex for safe identifiers.
@@ -14,9 +14,11 @@ const_regex! {
     /// contains further information why it is reasonable to restict
     /// names this way. This is not only useful for filenames, but for
     /// any identifier command line tools work with.
-    pub SAFE_ID_REGEX = concat!(r"^", SAFE_ID_REGEX_STR!(), r"$");
-    pub PASSWORD_REGEX = r"^[[:^cntrl:]]*$"; // everything but control characters
-    pub SINGLE_LINE_COMMENT_REGEX = r"^[[:^cntrl:]]*$"; // everything but control characters
+    pub SAFE_ID_REGEX = concatcp!(r"^", SAFE_ID_REGEX_STR, r"$");
+    /// Password. Allow everything but control characters.
+    pub PASSWORD_REGEX = r"^[[:^cntrl:]]*$";
+    /// Single line comment. Allow everything but control characters.
+    pub SINGLE_LINE_COMMENT_REGEX = r"^[[:^cntrl:]]*$";
 }
 
 pub const SAFE_ID_FORMAT: ApiStringFormat = ApiStringFormat::Pattern(&SAFE_ID_REGEX);
-- 
2.39.2




             reply	other threads:[~2024-03-15 11:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-15 11:27 Dietmar Maurer [this message]
2024-03-15 11:27 ` [pbs-devel] [PATCH proxmox 2/4] proxmox-auth-api: " Dietmar Maurer
2024-03-15 11:27 ` [pbs-devel] [PATCH proxmox 3/4] proxmox-schema: add IP address regex/api-types Dietmar Maurer
2024-03-15 11:27 ` [pbs-devel] [PATCH proxmox 4/4] proxmox-schema: moved common api types from pbs-api-types Dietmar Maurer
2024-03-19 10:14 ` [pbs-devel] applied-series: [PATCH proxmox 1/4] proxmox-schema: use const_format to define static strings Wolfgang Bumiller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240315112732.368831-1-dietmar@proxmox.com \
    --to=dietmar@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal