diff --git a/Cargo.lock b/Cargo.lock index 020ebb1..7f3eae9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -759,6 +759,7 @@ dependencies = [ "futures-util", "http-body-util", "hyper 1.0.0-rc.3", + "lazy_static", "nom", "prometheus", "quick-xml", diff --git a/Cargo.toml b/Cargo.toml index ec768ea..8cac874 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" +lazy_static = "1.4.0" 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..35d0dfc 100644 --- a/src/protos/xmpp/bind.rs +++ b/src/protos/xmpp/bind.rs @@ -42,10 +42,12 @@ 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 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) .ok_or(ffail!("Incorrectly format jid: {i}"))?;