proxmox-schema: use const_format to define static strings.
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>
This commit is contained in:
parent
c67a13f1d7
commit
0c5e2640d0
@ -55,6 +55,7 @@ base32 = "0.4"
|
|||||||
base64 = "0.13"
|
base64 = "0.13"
|
||||||
bitflags = "1.2.1"
|
bitflags = "1.2.1"
|
||||||
bytes = "1.0"
|
bytes = "1.0"
|
||||||
|
const_format = "0.2"
|
||||||
crc32fast = "1"
|
crc32fast = "1"
|
||||||
crossbeam-channel = "0.5"
|
crossbeam-channel = "0.5"
|
||||||
endian_trait = "0.6"
|
endian_trait = "0.6"
|
||||||
|
@ -11,6 +11,7 @@ exclude.workspace = true
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
|
const_format = { workspace = true, optional = true }
|
||||||
lazy_static.workspace = true
|
lazy_static.workspace = true
|
||||||
regex.workspace = true
|
regex.workspace = true
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
@ -33,7 +34,7 @@ default = []
|
|||||||
|
|
||||||
api-macro = ["dep:proxmox-api-macro"]
|
api-macro = ["dep:proxmox-api-macro"]
|
||||||
upid-api-impl = [ "dep:libc", "dep:nix" ]
|
upid-api-impl = [ "dep:libc", "dep:nix" ]
|
||||||
api-types = []
|
api-types = [ "dep:const_format" ]
|
||||||
|
|
||||||
# Testing only
|
# Testing only
|
||||||
test-harness = []
|
test-harness = []
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
//! The "basic" api types we generally require along with some of their macros.
|
//! The "basic" api types we generally require along with some of their macros.
|
||||||
|
use const_format::concatcp;
|
||||||
|
|
||||||
use crate::{ApiStringFormat, Schema, StringSchema};
|
use crate::{ApiStringFormat, Schema, StringSchema};
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
#[macro_export]
|
const SAFE_ID_REGEX_STR: &str = r"(?:[A-Za-z0-9_][A-Za-z0-9._\-]*)";
|
||||||
macro_rules! SAFE_ID_REGEX_STR { () => { r"(?:[A-Za-z0-9_][A-Za-z0-9._\-]*)" }; }
|
|
||||||
|
|
||||||
const_regex! {
|
const_regex! {
|
||||||
/// Regex for safe identifiers.
|
/// Regex for safe identifiers.
|
||||||
@ -14,9 +14,11 @@ const_regex! {
|
|||||||
/// contains further information why it is reasonable to restict
|
/// contains further information why it is reasonable to restict
|
||||||
/// names this way. This is not only useful for filenames, but for
|
/// names this way. This is not only useful for filenames, but for
|
||||||
/// any identifier command line tools work with.
|
/// any identifier command line tools work with.
|
||||||
pub SAFE_ID_REGEX = concat!(r"^", SAFE_ID_REGEX_STR!(), r"$");
|
pub SAFE_ID_REGEX = concatcp!(r"^", SAFE_ID_REGEX_STR, r"$");
|
||||||
pub PASSWORD_REGEX = r"^[[:^cntrl:]]*$"; // everything but control characters
|
/// Password. Allow everything but control characters.
|
||||||
pub SINGLE_LINE_COMMENT_REGEX = r"^[[:^cntrl:]]*$"; // 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);
|
pub const SAFE_ID_FORMAT: ApiStringFormat = ApiStringFormat::Pattern(&SAFE_ID_REGEX);
|
||||||
|
Loading…
Reference in New Issue
Block a user