From 52d2834e98149d51177f349391be3a5b5bb02105 Mon Sep 17 00:00:00 2001 From: Slatian Date: Tue, 6 Aug 2024 18:35:00 +0200 Subject: [PATCH] Replace lazy_static crate with "new" std::sync::LazyLock --- Cargo.lock | 1 - Cargo.toml | 1 - src/main.rs | 9 +++------ 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e538a48..e65ebbd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -494,7 +494,6 @@ dependencies = [ "hickory-resolver", "http 1.1.0", "idna 0.5.0", - "lazy_static", "lib-humus", "maxminddb", "mime", diff --git a/Cargo.toml b/Cargo.toml index da959dc..e658b6d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,6 @@ axum-client-ip = "0.6" clap = { version = "4.5", features = ["derive"] } governor = "0.6" idna = "0.5" -lazy_static = "1.4.0" parking_lot = "0.12" regex = "1.10" serde = { version = "1", features = ["derive","rc"] } diff --git a/src/main.rs b/src/main.rs index b0f922c..6e4f73f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,6 @@ use axum_client_ip::SecureClientIp; use axum_extra::headers; use axum_extra::TypedHeader; use clap::Parser; -use lazy_static::lazy_static; use regex::Regex; use serde::{Deserialize,Serialize}; use tower::ServiceBuilder; @@ -34,6 +33,7 @@ use tokio::task; use std::collections::HashMap; use std::net::IpAddr; use std::sync::Arc; +use std::sync::LazyLock; use lib_humus::TemplateEngineLoader; use lib_humus::read_toml_from_file; @@ -443,6 +443,8 @@ async fn handle_default_route( ) } +static ASN_REGEX: LazyLock = LazyLock::new(|| { Regex::new(r"^[Aa][Ss][Nn]?\s*(\d{1,7})$").unwrap() }); +static VIA_REGEX: LazyLock = LazyLock::new(|| { Regex::new(r"[Vv][Ii][Aa]\s+(\S+)").unwrap() }); async fn handle_search_request( search_query: String, @@ -455,11 +457,6 @@ async fn handle_search_request( let mut search_query = search_query.trim().to_string(); let mut settings = settings; - lazy_static!{ - static ref ASN_REGEX: Regex = Regex::new(r"^[Aa][Ss][Nn]?\s*(\d{1,7})$").unwrap(); - static ref VIA_REGEX: Regex = Regex::new(r"[Vv][Ii][Aa]\s+(\S+)").unwrap(); - } - //If someone asked for an asn, give an asn answer if let Some(asn_cap) = ASN_REGEX.captures(&search_query) { if let Some(asn) = asn_cap.get(1).map_or(None, |m| m.as_str().parse::().ok()) {