mirror of
https://github.com/eza-community/eza
synced 2024-10-14 20:03:50 +00:00
refactor: replace lazy_static
with once_cell
This commit is contained in:
parent
a41a8208cf
commit
cc691f5dbe
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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>,
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue