chore: use LazyLock instead of lazy_static!
This commit is contained in:
parent
a20d77fea4
commit
97027e69c3
4 changed files with 15 additions and 23 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -1519,7 +1519,6 @@ dependencies = [
|
|||
"icu_provider 1.5.0",
|
||||
"indexmap",
|
||||
"itertools 0.14.0",
|
||||
"lazy_static",
|
||||
"libcosmic",
|
||||
"log",
|
||||
"open",
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ hex_color = { version = "3", features = ["serde"] }
|
|||
indexmap = "2"
|
||||
#TODO: for repeat_n, which is in std in 1.82
|
||||
itertools = "0.14"
|
||||
lazy_static = "1"
|
||||
log = "0.4"
|
||||
open = "5.3.2"
|
||||
palette = { version = "0.7", features = ["serde"] }
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use std::str::FromStr;
|
||||
use std::{str::FromStr, sync::LazyLock};
|
||||
|
||||
use i18n_embed::{
|
||||
fluent::{fluent_language_loader, FluentLanguageLoader},
|
||||
|
|
@ -14,20 +14,17 @@ use rust_embed::RustEmbed;
|
|||
#[folder = "i18n/"]
|
||||
struct Localizations;
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
pub static ref LANGUAGE_LOADER: FluentLanguageLoader = {
|
||||
let loader: FluentLanguageLoader = fluent_language_loader!();
|
||||
pub static LANGUAGE_LOADER: LazyLock<FluentLanguageLoader> = LazyLock::new(|| {
|
||||
let loader: FluentLanguageLoader = fluent_language_loader!();
|
||||
|
||||
loader
|
||||
.load_fallback_language(&Localizations)
|
||||
.expect("Error while loading fallback language");
|
||||
loader
|
||||
.load_fallback_language(&Localizations)
|
||||
.expect("Error while loading fallback language");
|
||||
|
||||
loader
|
||||
};
|
||||
}
|
||||
loader
|
||||
});
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
pub static ref LANGUAGE_SORTER: Collator = {
|
||||
pub static LANGUAGE_SORTER: LazyLock<Collator> = LazyLock::new(|| {
|
||||
let mut options = CollatorOptions::new();
|
||||
options.numeric = Some(Numeric::On);
|
||||
|
||||
|
|
@ -40,8 +37,7 @@ lazy_static::lazy_static! {
|
|||
Collator::try_new(&locale, options).ok()
|
||||
})
|
||||
.expect("Creating a collator from the system's current language, the fallback language, or American English should succeed")
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! fl {
|
||||
|
|
|
|||
12
src/main.rs
12
src/main.rs
|
|
@ -33,9 +33,11 @@ use std::{
|
|||
any::TypeId,
|
||||
cmp,
|
||||
collections::{BTreeMap, BTreeSet, HashMap},
|
||||
env, fs, process,
|
||||
env,
|
||||
error::Error,
|
||||
fs, process,
|
||||
rc::Rc,
|
||||
sync::{atomic::Ordering, Mutex},
|
||||
sync::{atomic::Ordering, LazyLock, Mutex},
|
||||
};
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
|
|
@ -71,11 +73,7 @@ mod dnd;
|
|||
|
||||
use clap_lex::RawArgs;
|
||||
|
||||
use std::error::Error;
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref ICON_CACHE: Mutex<IconCache> = Mutex::new(IconCache::new());
|
||||
}
|
||||
static ICON_CACHE: LazyLock<Mutex<IconCache>> = LazyLock::new(|| Mutex::new(IconCache::new()));
|
||||
|
||||
pub fn icon_cache_get(name: &'static str, size: u16) -> widget::icon::Icon {
|
||||
let mut icon_cache = ICON_CACHE.lock().unwrap();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue