Skip to content

Commit 7db3c7b

Browse files
erwinvaneijkcafkafk
authored andcommitted
feat(once_cell): remove dependency on once_cell
Rust 1.80+ has a proper implementation of LazyLock, which, when used, removes the dependency on once_cell. - remove once_cell from dependencies Fixes: #1169
1 parent 0f0d99c commit 7db3c7b

File tree

5 files changed

+10
-13
lines changed

5 files changed

+10
-13
lines changed

Cargo.lock

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ natord-plus-plus = "2.0"
9898
path-clean = "1.0.1"
9999
number_prefix = "0.4"
100100
palette = { version = "0.7.6", default-features = false, features = ["std"] }
101-
once_cell = "1.21.0"
102101
percent-encoding = "2.3.1"
103102
phf = { version = "0.11.2", features = ["macros"] }
104103
plist = { version = "1.7.0", default-features = false }

src/fs/file.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use chrono::prelude::*;
2626

2727
use log::*;
2828
#[cfg(unix)]
29-
use once_cell::sync::Lazy;
29+
use std::sync::LazyLock;
3030

3131
use crate::fs::dir::Dir;
3232
use crate::fs::feature::xattr;
@@ -41,11 +41,10 @@ use super::mounts::MountedFs;
4141
// Maps (device_id, inode) => (size_in_bytes, size_in_blocks)
4242
// Mutex::new is const but HashMap::new is not const requiring us to use lazy
4343
// initialization.
44-
// TODO: Replace with std::sync::LazyLock when it is stable.
4544
#[allow(clippy::type_complexity)]
4645
#[cfg(unix)]
47-
static DIRECTORY_SIZE_CACHE: Lazy<Mutex<HashMap<(u64, u64), (u64, u64)>>> =
48-
Lazy::new(|| Mutex::new(HashMap::new()));
46+
static DIRECTORY_SIZE_CACHE: LazyLock<Mutex<HashMap<(u64, u64), (u64, u64)>>> =
47+
LazyLock::new(|| Mutex::new(HashMap::new()));
4948

5049
/// A **File** is a wrapper around one of Rust’s `PathBuf` values, along with
5150
/// associated data about the file.

src/output/table.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::sync::{Mutex, MutexGuard};
1212
use chrono::prelude::*;
1313

1414
use log::*;
15-
use once_cell::sync::Lazy;
15+
use std::sync::LazyLock;
1616
#[cfg(unix)]
1717
use uzers::UsersCache;
1818

@@ -398,7 +398,7 @@ impl Environment {
398398
}
399399
}
400400

401-
static ENVIRONMENT: Lazy<Environment> = Lazy::new(Environment::load_all);
401+
static ENVIRONMENT: LazyLock<Environment> = LazyLock::new(Environment::load_all);
402402

403403
pub struct Table<'a> {
404404
columns: Vec<Column>,

src/output/time.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
99
use chrono::prelude::*;
1010
use core::cmp::max;
11-
use once_cell::sync::Lazy;
11+
use std::sync::LazyLock;
1212
use std::time::Duration;
1313
use unicode_width::UnicodeWidthStr;
1414

@@ -140,12 +140,12 @@ fn custom(time: &DateTime<FixedOffset>, non_recent_fmt: &str, recent_fmt: Option
140140
}
141141
}
142142

143-
static CURRENT_YEAR: Lazy<i32> = Lazy::new(|| Local::now().year());
143+
static CURRENT_YEAR: LazyLock<i32> = LazyLock::new(|| Local::now().year());
144144

145-
static LOCALE: Lazy<locale::Time> =
146-
Lazy::new(|| locale::Time::load_user_locale().unwrap_or_else(|_| locale::Time::english()));
145+
static LOCALE: LazyLock<locale::Time> =
146+
LazyLock::new(|| locale::Time::load_user_locale().unwrap_or_else(|_| locale::Time::english()));
147147

148-
static MAX_MONTH_WIDTH: Lazy<usize> = Lazy::new(|| {
148+
static MAX_MONTH_WIDTH: LazyLock<usize> = LazyLock::new(|| {
149149
// Some locales use a three-character wide month name (Jan to Dec);
150150
// others vary between three to four (1月 to 12月, juil.). We check each month width
151151
// to detect the longest and set the output format accordingly.

0 commit comments

Comments
 (0)