Replace lazy_static crate with "new" std::sync::LazyLock

This commit is contained in:
Slatian 2024-08-06 18:35:00 +02:00
parent da391003e4
commit 52d2834e98
3 changed files with 3 additions and 8 deletions

1
Cargo.lock generated
View File

@ -494,7 +494,6 @@ dependencies = [
"hickory-resolver", "hickory-resolver",
"http 1.1.0", "http 1.1.0",
"idna 0.5.0", "idna 0.5.0",
"lazy_static",
"lib-humus", "lib-humus",
"maxminddb", "maxminddb",
"mime", "mime",

View File

@ -15,7 +15,6 @@ axum-client-ip = "0.6"
clap = { version = "4.5", features = ["derive"] } clap = { version = "4.5", features = ["derive"] }
governor = "0.6" governor = "0.6"
idna = "0.5" idna = "0.5"
lazy_static = "1.4.0"
parking_lot = "0.12" parking_lot = "0.12"
regex = "1.10" regex = "1.10"
serde = { version = "1", features = ["derive","rc"] } serde = { version = "1", features = ["derive","rc"] }

View File

@ -17,7 +17,6 @@ use axum_client_ip::SecureClientIp;
use axum_extra::headers; use axum_extra::headers;
use axum_extra::TypedHeader; use axum_extra::TypedHeader;
use clap::Parser; use clap::Parser;
use lazy_static::lazy_static;
use regex::Regex; use regex::Regex;
use serde::{Deserialize,Serialize}; use serde::{Deserialize,Serialize};
use tower::ServiceBuilder; use tower::ServiceBuilder;
@ -34,6 +33,7 @@ use tokio::task;
use std::collections::HashMap; use std::collections::HashMap;
use std::net::IpAddr; use std::net::IpAddr;
use std::sync::Arc; use std::sync::Arc;
use std::sync::LazyLock;
use lib_humus::TemplateEngineLoader; use lib_humus::TemplateEngineLoader;
use lib_humus::read_toml_from_file; use lib_humus::read_toml_from_file;
@ -443,6 +443,8 @@ async fn handle_default_route(
) )
} }
static ASN_REGEX: LazyLock<Regex> = LazyLock::new(|| { Regex::new(r"^[Aa][Ss][Nn]?\s*(\d{1,7})$").unwrap() });
static VIA_REGEX: LazyLock<Regex> = LazyLock::new(|| { Regex::new(r"[Vv][Ii][Aa]\s+(\S+)").unwrap() });
async fn handle_search_request( async fn handle_search_request(
search_query: String, search_query: String,
@ -455,11 +457,6 @@ async fn handle_search_request(
let mut search_query = search_query.trim().to_string(); let mut search_query = search_query.trim().to_string();
let mut settings = settings; 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 someone asked for an asn, give an asn answer
if let Some(asn_cap) = ASN_REGEX.captures(&search_query) { 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::<u32>().ok()) { if let Some(asn) = asn_cap.get(1).map_or(None, |m| m.as_str().parse::<u32>().ok()) {