chore: use LazyLock instead of lazy_static!

This commit is contained in:
Doods 2025-07-13 15:50:37 +03:00
parent a20d77fea4
commit 97027e69c3
4 changed files with 15 additions and 23 deletions

1
Cargo.lock generated
View file

@ -1519,7 +1519,6 @@ dependencies = [
"icu_provider 1.5.0", "icu_provider 1.5.0",
"indexmap", "indexmap",
"itertools 0.14.0", "itertools 0.14.0",
"lazy_static",
"libcosmic", "libcosmic",
"log", "log",
"open", "open",

View file

@ -16,7 +16,6 @@ hex_color = { version = "3", features = ["serde"] }
indexmap = "2" indexmap = "2"
#TODO: for repeat_n, which is in std in 1.82 #TODO: for repeat_n, which is in std in 1.82
itertools = "0.14" itertools = "0.14"
lazy_static = "1"
log = "0.4" log = "0.4"
open = "5.3.2" open = "5.3.2"
palette = { version = "0.7", features = ["serde"] } palette = { version = "0.7", features = ["serde"] }

View file

@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-only // SPDX-License-Identifier: GPL-3.0-only
use std::str::FromStr; use std::{str::FromStr, sync::LazyLock};
use i18n_embed::{ use i18n_embed::{
fluent::{fluent_language_loader, FluentLanguageLoader}, fluent::{fluent_language_loader, FluentLanguageLoader},
@ -14,20 +14,17 @@ use rust_embed::RustEmbed;
#[folder = "i18n/"] #[folder = "i18n/"]
struct Localizations; struct Localizations;
lazy_static::lazy_static! { pub static LANGUAGE_LOADER: LazyLock<FluentLanguageLoader> = LazyLock::new(|| {
pub static ref LANGUAGE_LOADER: FluentLanguageLoader = { let loader: FluentLanguageLoader = fluent_language_loader!();
let loader: FluentLanguageLoader = fluent_language_loader!();
loader loader
.load_fallback_language(&Localizations) .load_fallback_language(&Localizations)
.expect("Error while loading fallback language"); .expect("Error while loading fallback language");
loader loader
}; });
}
lazy_static::lazy_static! { pub static LANGUAGE_SORTER: LazyLock<Collator> = LazyLock::new(|| {
pub static ref LANGUAGE_SORTER: Collator = {
let mut options = CollatorOptions::new(); let mut options = CollatorOptions::new();
options.numeric = Some(Numeric::On); options.numeric = Some(Numeric::On);
@ -40,8 +37,7 @@ lazy_static::lazy_static! {
Collator::try_new(&locale, options).ok() Collator::try_new(&locale, options).ok()
}) })
.expect("Creating a collator from the system's current language, the fallback language, or American English should succeed") .expect("Creating a collator from the system's current language, the fallback language, or American English should succeed")
}; });
}
#[macro_export] #[macro_export]
macro_rules! fl { macro_rules! fl {

View file

@ -33,9 +33,11 @@ use std::{
any::TypeId, any::TypeId,
cmp, cmp,
collections::{BTreeMap, BTreeSet, HashMap}, collections::{BTreeMap, BTreeSet, HashMap},
env, fs, process, env,
error::Error,
fs, process,
rc::Rc, rc::Rc,
sync::{atomic::Ordering, Mutex}, sync::{atomic::Ordering, LazyLock, Mutex},
}; };
use tokio::sync::mpsc; use tokio::sync::mpsc;
@ -71,11 +73,7 @@ mod dnd;
use clap_lex::RawArgs; use clap_lex::RawArgs;
use std::error::Error; static ICON_CACHE: LazyLock<Mutex<IconCache>> = LazyLock::new(|| Mutex::new(IconCache::new()));
lazy_static::lazy_static! {
static ref ICON_CACHE: Mutex<IconCache> = Mutex::new(IconCache::new());
}
pub fn icon_cache_get(name: &'static str, size: u16) -> widget::icon::Icon { pub fn icon_cache_get(name: &'static str, size: u16) -> widget::icon::Icon {
let mut icon_cache = ICON_CACHE.lock().unwrap(); let mut icon_cache = ICON_CACHE.lock().unwrap();