diff --git a/Cargo.lock b/Cargo.lock index 020ebb1..573a05b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -763,6 +763,7 @@ dependencies = [ "prometheus", "quick-xml", "regex", + "regex_static", "reqwest", "rustls-pemfile", "serde", @@ -1210,7 +1211,7 @@ dependencies = [ "aho-corasick", "memchr", "regex-automata", - "regex-syntax", + "regex-syntax 0.7.4", ] [[package]] @@ -1221,15 +1222,55 @@ checksum = "b7b6d6190b7594385f61bd3911cd1be99dfddcfc365a4160cc2ab5bff4aed294" dependencies = [ "aho-corasick", "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]] name = "regex-syntax" version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" 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]] name = "reqwest" version = "0.11.18" diff --git a/Cargo.toml b/Cargo.toml index ec768ea..cf187bf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ tracing-subscriber = "0.3.16" futures-util = "0.3.25" prometheus = { version = "0.13.3", default-features = false } regex = "1.7.1" +regex_static = "0.1.1" nom = "7.1.3" tokio-rustls = "0.24.1" rustls-pemfile = "1.0.2" diff --git a/src/protos/xmpp/bind.rs b/src/protos/xmpp/bind.rs index e89e548..c0ee7d3 100644 --- a/src/protos/xmpp/bind.rs +++ b/src/protos/xmpp/bind.rs @@ -42,9 +42,7 @@ impl Display for Jid { impl Jid { pub fn from_string(i: &str) -> Result { - // TODO make regex static - use regex::Regex; - let re = Regex::new(r"^(([a-zA-Z]+)@)?([a-zA-Z.]+)(/([a-zA-Z\-]+))?$").unwrap(); + let re = regex_static::static_regex!(r"^(([a-zA-Z]+)@)?([a-zA-Z.]+)(/([a-zA-Z\-]+))?$"); let m = re .captures(i) .ok_or(ffail!("Incorrectly format jid: {i}"))?;