used lazy_static

This commit is contained in:
JustTestingV 2023-08-26 18:47:29 +03:00
parent 82a18f7d12
commit fd6aeeda8a
3 changed files with 10 additions and 46 deletions

46
Cargo.lock generated
View File

@ -759,11 +759,11 @@ dependencies = [
"futures-util", "futures-util",
"http-body-util", "http-body-util",
"hyper 1.0.0-rc.3", "hyper 1.0.0-rc.3",
"lazy_static",
"nom", "nom",
"prometheus", "prometheus",
"quick-xml", "quick-xml",
"regex", "regex",
"regex_static",
"reqwest", "reqwest",
"rustls-pemfile", "rustls-pemfile",
"serde", "serde",
@ -1211,7 +1211,7 @@ dependencies = [
"aho-corasick", "aho-corasick",
"memchr", "memchr",
"regex-automata", "regex-automata",
"regex-syntax 0.7.4", "regex-syntax",
] ]
[[package]] [[package]]
@ -1222,55 +1222,15 @@ checksum = "b7b6d6190b7594385f61bd3911cd1be99dfddcfc365a4160cc2ab5bff4aed294"
dependencies = [ dependencies = [
"aho-corasick", "aho-corasick",
"memchr", "memchr",
"regex-syntax 0.7.4", "regex-syntax",
] ]
[[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,7 +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" lazy_static = "1.4.0"
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,8 +42,12 @@ impl Display for Jid {
impl Jid { impl Jid {
pub fn from_string(i: &str) -> Result<Jid> { pub fn from_string(i: &str) -> Result<Jid> {
let re = regex_static::static_regex!(r"^(([a-zA-Z]+)@)?([a-zA-Z.]+)(/([a-zA-Z\-]+))?$"); use regex::Regex;
let m = re use lazy_static::lazy_static;
lazy_static! {
static ref RE: Regex = Regex::new(r"^(([a-zA-Z]+)@)?([a-zA-Z.]+)(/([a-zA-Z\-]+))?$").unwrap();
}
let m = RE
.captures(i) .captures(i)
.ok_or(ffail!("Incorrectly format jid: {i}"))?; .ok_or(ffail!("Incorrectly format jid: {i}"))?;