refactor: replace lazy_static with once_cell

This commit is contained in:
Lena 2023-10-19 21:05:52 +02:00
parent a41a8208cf
commit cc691f5dbe
No known key found for this signature in database
GPG key ID: AB5FC04C3C94443F
4 changed files with 15 additions and 27 deletions

7
Cargo.lock generated
View file

@ -363,7 +363,6 @@ dependencies = [
"criterion",
"git2",
"glob",
"lazy_static",
"libc",
"locale",
"log",
@ -555,12 +554,6 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.149"

View file

@ -74,7 +74,6 @@ name = "eza"
ansiterm = "0.12.2"
chrono = { version = "0.4.31", default-features = false, features = ["clock"] }
glob = "0.3"
lazy_static = "1.3"
libc = "0.2"
locale = "0.2"
log = "0.4"

View file

@ -5,8 +5,8 @@ use std::sync::{Mutex, MutexGuard};
use chrono::prelude::*;
use lazy_static::lazy_static;
use log::*;
use once_cell::sync::Lazy;
#[cfg(unix)]
use uzers::UsersCache;
@ -352,9 +352,7 @@ impl Environment {
}
}
lazy_static! {
static ref ENVIRONMENT: Environment = Environment::load_all();
}
static ENVIRONMENT: Lazy<Environment> = Lazy::new(Environment::load_all);
pub struct Table<'a> {
columns: Vec<Column>,

View file

@ -2,7 +2,7 @@
use chrono::prelude::*;
use core::cmp::max;
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use std::time::Duration;
use unicode_width::UnicodeWidthStr;
@ -119,22 +119,20 @@ fn custom(time: &DateTime<FixedOffset>, fmt: &str) -> String {
time.format(fmt).to_string()
}
lazy_static! {
static CURRENT_YEAR: Lazy<i32> = Lazy::new(|| Local::now().year());
static ref CURRENT_YEAR: i32 = Local::now().year();
static LOCALE: Lazy<locale::Time> =
Lazy::new(|| locale::Time::load_user_locale().unwrap_or_else(|_| locale::Time::english()));
static ref LOCALE: locale::Time = {
locale::Time::load_user_locale()
.unwrap_or_else(|_| locale::Time::english())
};
static ref MAX_MONTH_WIDTH: usize = {
// Some locales use a three-character wide month name (Jan to Dec);
// others vary between three to four (1月 to 12月, juil.). We check each month width
// to detect the longest and set the output format accordingly.
(0..11).map(|i| UnicodeWidthStr::width(&*LOCALE.short_month_name(i))).max().unwrap()
};
}
static MAX_MONTH_WIDTH: Lazy<usize> = Lazy::new(|| {
// Some locales use a three-character wide month name (Jan to Dec);
// others vary between three to four (1月 to 12月, juil.). We check each month width
// to detect the longest and set the output format accordingly.
(0..11)
.map(|i| UnicodeWidthStr::width(&*LOCALE.short_month_name(i)))
.max()
.unwrap()
});
#[cfg(test)]
mod test {