used regex_static in Jid

This commit is contained in:
JustTestingV 2023-08-26 18:10:27 +03:00
parent 6ed1f6be40
commit 82a18f7d12
3 changed files with 45 additions and 5 deletions

45
Cargo.lock generated
View File

@ -763,6 +763,7 @@ dependencies = [
"prometheus", "prometheus",
"quick-xml", "quick-xml",
"regex", "regex",
"regex_static",
"reqwest", "reqwest",
"rustls-pemfile", "rustls-pemfile",
"serde", "serde",
@ -1210,7 +1211,7 @@ dependencies = [
"aho-corasick", "aho-corasick",
"memchr", "memchr",
"regex-automata", "regex-automata",
"regex-syntax", "regex-syntax 0.7.4",
] ]
[[package]] [[package]]
@ -1221,15 +1222,55 @@ checksum = "b7b6d6190b7594385f61bd3911cd1be99dfddcfc365a4160cc2ab5bff4aed294"
dependencies = [ dependencies = [
"aho-corasick", "aho-corasick",
"memchr", "memchr",
"regex-syntax", "regex-syntax 0.7.4",
] ]
[[package]]
name = "regex-syntax"
version = "0.6.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
[[package]] [[package]]
name = "regex-syntax" name = "regex-syntax"
version = "0.7.4" version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2"
[[package]]
name = "regex_static"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6126d61c5e4b41929098f73b42fc1d257116cc95d19739248c51591f77cc0021"
dependencies = [
"once_cell",
"regex",
"regex_static_macro",
]
[[package]]
name = "regex_static_impl"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c3755019886a70e772e6360b0b58501d75cf7dc17a53e08aa97e59ecb2c2bc5"
dependencies = [
"proc-macro2",
"quote",
"regex-syntax 0.6.29",
"syn 1.0.109",
]
[[package]]
name = "regex_static_macro"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79b15495fd034158635bc8b762a132dfc83864d6992aeda1ffabf01b03b611a1"
dependencies = [
"proc-macro2",
"regex_static_impl",
"syn 1.0.109",
]
[[package]] [[package]]
name = "reqwest" name = "reqwest"
version = "0.11.18" version = "0.11.18"

View File

@ -16,6 +16,7 @@ tracing-subscriber = "0.3.16"
futures-util = "0.3.25" futures-util = "0.3.25"
prometheus = { version = "0.13.3", default-features = false } prometheus = { version = "0.13.3", default-features = false }
regex = "1.7.1" regex = "1.7.1"
regex_static = "0.1.1"
nom = "7.1.3" nom = "7.1.3"
tokio-rustls = "0.24.1" tokio-rustls = "0.24.1"
rustls-pemfile = "1.0.2" rustls-pemfile = "1.0.2"

View File

@ -42,9 +42,7 @@ impl Display for Jid {
impl Jid { impl Jid {
pub fn from_string(i: &str) -> Result<Jid> { pub fn from_string(i: &str) -> Result<Jid> {
// TODO make regex static let re = regex_static::static_regex!(r"^(([a-zA-Z]+)@)?([a-zA-Z.]+)(/([a-zA-Z\-]+))?$");
use regex::Regex;
let re = Regex::new(r"^(([a-zA-Z]+)@)?([a-zA-Z.]+)(/([a-zA-Z\-]+))?$").unwrap();
let m = re let m = re
.captures(i) .captures(i)
.ok_or(ffail!("Incorrectly format jid: {i}"))?; .ok_or(ffail!("Incorrectly format jid: {i}"))?;