build(deps): migrate usages of once_cell crate to standard library equivalents (#8030)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Sanchith Hegde
2025-05-19 15:54:03 +05:30
committed by GitHub
parent da90d74bfa
commit 673cf249b0
32 changed files with 176 additions and 183 deletions

View File

@ -1,6 +1,7 @@
use std::{
collections::{HashMap, HashSet},
str::FromStr,
sync::LazyLock,
};
#[cfg(feature = "payouts")]
@ -24,7 +25,6 @@ use hyperswitch_domain_models::{
network_tokenization::NetworkTokenNumber, payments::payment_attempt::PaymentAttempt,
};
use masking::{Deserialize, ExposeInterface, Secret};
use once_cell::sync::Lazy;
use regex::Regex;
#[cfg(feature = "frm")]
@ -1346,29 +1346,31 @@ impl From<domain::GooglePayWalletData> for GooglePayWalletData {
}
}
static CARD_REGEX: Lazy<HashMap<CardIssuer, Result<Regex, regex::Error>>> = Lazy::new(|| {
let mut map = HashMap::new();
// Reference: https://gist.github.com/michaelkeevildown/9096cd3aac9029c4e6e05588448a8841
// [#379]: Determine card issuer from card BIN number
map.insert(CardIssuer::Master, Regex::new(r"^5[1-5][0-9]{14}$"));
map.insert(CardIssuer::AmericanExpress, Regex::new(r"^3[47][0-9]{13}$"));
map.insert(CardIssuer::Visa, Regex::new(r"^4[0-9]{12}(?:[0-9]{3})?$"));
map.insert(CardIssuer::Discover, Regex::new(r"^65[4-9][0-9]{13}|64[4-9][0-9]{13}|6011[0-9]{12}|(622(?:12[6-9]|1[3-9][0-9]|[2-8][0-9][0-9]|9[01][0-9]|92[0-5])[0-9]{10})$"));
map.insert(
CardIssuer::Maestro,
Regex::new(r"^(5018|5020|5038|5893|6304|6759|6761|6762|6763)[0-9]{8,15}$"),
);
map.insert(
CardIssuer::DinersClub,
Regex::new(r"^3(?:0[0-5]|[68][0-9])[0-9]{11}$"),
);
map.insert(
CardIssuer::JCB,
Regex::new(r"^(3(?:088|096|112|158|337|5(?:2[89]|[3-8][0-9]))\d{12})$"),
);
map.insert(CardIssuer::CarteBlanche, Regex::new(r"^389[0-9]{11}$"));
map
});
static CARD_REGEX: LazyLock<HashMap<CardIssuer, Result<Regex, regex::Error>>> = LazyLock::new(
|| {
let mut map = HashMap::new();
// Reference: https://gist.github.com/michaelkeevildown/9096cd3aac9029c4e6e05588448a8841
// [#379]: Determine card issuer from card BIN number
map.insert(CardIssuer::Master, Regex::new(r"^5[1-5][0-9]{14}$"));
map.insert(CardIssuer::AmericanExpress, Regex::new(r"^3[47][0-9]{13}$"));
map.insert(CardIssuer::Visa, Regex::new(r"^4[0-9]{12}(?:[0-9]{3})?$"));
map.insert(CardIssuer::Discover, Regex::new(r"^65[4-9][0-9]{13}|64[4-9][0-9]{13}|6011[0-9]{12}|(622(?:12[6-9]|1[3-9][0-9]|[2-8][0-9][0-9]|9[01][0-9]|92[0-5])[0-9]{10})$"));
map.insert(
CardIssuer::Maestro,
Regex::new(r"^(5018|5020|5038|5893|6304|6759|6761|6762|6763)[0-9]{8,15}$"),
);
map.insert(
CardIssuer::DinersClub,
Regex::new(r"^3(?:0[0-5]|[68][0-9])[0-9]{11}$"),
);
map.insert(
CardIssuer::JCB,
Regex::new(r"^(3(?:088|096|112|158|337|5(?:2[89]|[3-8][0-9]))\d{12})$"),
);
map.insert(CardIssuer::CarteBlanche, Regex::new(r"^389[0-9]{11}$"));
map
},
);
#[derive(Debug, Copy, Clone, strum::Display, Eq, Hash, PartialEq)]
pub enum CardIssuer {

View File

@ -1,4 +1,7 @@
use std::collections::{HashMap, HashSet};
use std::{
collections::{HashMap, HashSet},
sync::LazyLock,
};
use api_models::{
user as user_api,
@ -11,7 +14,6 @@ use diesel_models::{
};
use error_stack::{report, ResultExt};
use masking::Secret;
use once_cell::sync::Lazy;
use crate::{
core::errors::{StorageErrorExt, UserErrors, UserResponse},
@ -51,26 +53,27 @@ pub async fn get_authorization_info_with_groups(
pub async fn get_authorization_info_with_group_tag(
) -> UserResponse<user_role_api::AuthorizationInfoResponse> {
static GROUPS_WITH_PARENT_TAGS: Lazy<Vec<user_role_api::ParentInfo>> = Lazy::new(|| {
PermissionGroup::iter()
.map(|group| (group.parent(), group))
.fold(
HashMap::new(),
|mut acc: HashMap<ParentGroup, Vec<PermissionGroup>>, (key, value)| {
acc.entry(key).or_default().push(value);
acc
},
)
.into_iter()
.filter_map(|(name, value)| {
Some(user_role_api::ParentInfo {
name: name.clone(),
description: info::get_parent_group_description(name)?,
groups: value,
static GROUPS_WITH_PARENT_TAGS: LazyLock<Vec<user_role_api::ParentInfo>> =
LazyLock::new(|| {
PermissionGroup::iter()
.map(|group| (group.parent(), group))
.fold(
HashMap::new(),
|mut acc: HashMap<ParentGroup, Vec<PermissionGroup>>, (key, value)| {
acc.entry(key).or_default().push(value);
acc
},
)
.into_iter()
.filter_map(|(name, value)| {
Some(user_role_api::ParentInfo {
name: name.clone(),
description: info::get_parent_group_description(name)?,
groups: value,
})
})
})
.collect()
});
.collect()
});
Ok(ApplicationResponse::Json(
user_role_api::AuthorizationInfoResponse(

View File

@ -1,12 +1,11 @@
use std::collections::HashMap;
use std::{collections::HashMap, sync::LazyLock};
use common_enums::{EntityType, PermissionGroup, RoleScope};
use once_cell::sync::Lazy;
use super::RoleInfo;
use crate::consts;
pub static PREDEFINED_ROLES: Lazy<HashMap<&'static str, RoleInfo>> = Lazy::new(|| {
pub static PREDEFINED_ROLES: LazyLock<HashMap<&'static str, RoleInfo>> = LazyLock::new(|| {
let mut roles = HashMap::new();
// Internal Roles

View File

@ -2,6 +2,7 @@ use std::{
collections::HashSet,
ops::{Deref, Not},
str::FromStr,
sync::LazyLock,
};
use api_models::{
@ -21,7 +22,6 @@ use diesel_models::{
use error_stack::{report, ResultExt};
use hyperswitch_domain_models::api::ApplicationResponse;
use masking::{ExposeInterface, PeekInterface, Secret};
use once_cell::sync::Lazy;
use rand::distributions::{Alphanumeric, DistString};
use time::PrimitiveDateTime;
use unicode_segmentation::UnicodeSegmentation;
@ -90,7 +90,7 @@ impl TryFrom<pii::Email> for UserName {
#[derive(Clone, Debug)]
pub struct UserEmail(pii::Email);
static BLOCKED_EMAIL: Lazy<HashSet<String>> = Lazy::new(|| {
static BLOCKED_EMAIL: LazyLock<HashSet<String>> = LazyLock::new(|| {
let blocked_emails_content = include_str!("../../utils/user/blocker_emails.txt");
let blocked_emails: HashSet<String> = blocked_emails_content
.lines()

View File

@ -1,9 +1,10 @@
use std::sync::LazyLock;
use common_enums::{Owner, UserAuthType};
use diesel_models::UserAuthenticationMethod;
use once_cell::sync::Lazy;
pub static DEFAULT_USER_AUTH_METHOD: Lazy<UserAuthenticationMethod> =
Lazy::new(|| UserAuthenticationMethod {
pub static DEFAULT_USER_AUTH_METHOD: LazyLock<UserAuthenticationMethod> =
LazyLock::new(|| UserAuthenticationMethod {
id: String::from("hyperswitch_default"),
auth_id: String::from("hyperswitch"),
owner_id: String::from("hyperswitch"),

View File

@ -1,11 +1,15 @@
use std::{collections::HashMap, ops::Deref, str::FromStr, sync::Arc};
use std::{
collections::HashMap,
ops::Deref,
str::FromStr,
sync::{Arc, LazyLock},
};
use api_models::enums;
use common_utils::{date_time, errors::CustomResult, events::ApiEventMetric, ext_traits::AsyncExt};
use currency_conversion::types::{CurrencyFactors, ExchangeRates};
use error_stack::ResultExt;
use masking::PeekInterface;
use once_cell::sync::Lazy;
use redis_interface::DelReply;
use router_env::{instrument, tracing};
use rust_decimal::Decimal;
@ -32,8 +36,8 @@ pub struct FxExchangeRatesCacheEntry {
timestamp: i64,
}
static FX_EXCHANGE_RATES_CACHE: Lazy<RwLock<Option<FxExchangeRatesCacheEntry>>> =
Lazy::new(|| RwLock::new(None));
static FX_EXCHANGE_RATES_CACHE: LazyLock<RwLock<Option<FxExchangeRatesCacheEntry>>> =
LazyLock::new(|| RwLock::new(None));
impl ApiEventMetric for FxExchangeRatesCacheEntry {}