Drop once_cell dependency (#14198)

This PR drops the `once_cell` dependency from all Nu crates, replacing
uses of the
[`Lazy`](https://docs.rs/once_cell/latest/once_cell/sync/struct.Lazy.html)
type with its `std` equivalent,
[`LazyLock`](https://doc.rust-lang.org/std/sync/struct.LazyLock.html).
This commit is contained in:
Alex Ionescu 2024-10-29 17:33:46 +01:00 committed by GitHub
parent 74bd0e32cc
commit e104bccfb9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 44 additions and 53 deletions

6
Cargo.lock generated
View file

@ -3020,7 +3020,6 @@ dependencies = [
"nu-protocol", "nu-protocol",
"nu-test-support", "nu-test-support",
"nu-utils", "nu-utils",
"once_cell",
"percent-encoding", "percent-encoding",
"reedline", "reedline",
"rstest", "rstest",
@ -3164,7 +3163,6 @@ dependencies = [
"num-traits", "num-traits",
"nuon", "nuon",
"oem_cp", "oem_cp",
"once_cell",
"open", "open",
"os_pipe", "os_pipe",
"pathdiff", "pathdiff",
@ -3257,7 +3255,6 @@ dependencies = [
"nu-protocol", "nu-protocol",
"nu-table", "nu-table",
"nu-utils", "nu-utils",
"once_cell",
"ratatui", "ratatui",
"strip-ansi-escapes", "strip-ansi-escapes",
"terminal_size", "terminal_size",
@ -3477,7 +3474,6 @@ dependencies = [
"mach2", "mach2",
"nix 0.29.0", "nix 0.29.0",
"ntapi", "ntapi",
"once_cell",
"procfs", "procfs",
"sysinfo 0.32.0", "sysinfo 0.32.0",
"windows", "windows",
@ -3493,7 +3489,6 @@ dependencies = [
"nu-engine", "nu-engine",
"nu-protocol", "nu-protocol",
"nu-utils", "nu-utils",
"once_cell",
"tabled", "tabled",
"terminal_size", "terminal_size",
] ]
@ -3528,7 +3523,6 @@ dependencies = [
"lscolors", "lscolors",
"nix 0.29.0", "nix 0.29.0",
"num-format", "num-format",
"once_cell",
"serde", "serde",
"strip-ansi-escapes", "strip-ansi-escapes",
"sys-locale", "sys-locale",

View file

@ -119,7 +119,6 @@ num-format = "0.4"
num-traits = "0.2" num-traits = "0.2"
oem_cp = "2.0.0" oem_cp = "2.0.0"
omnipath = "0.1" omnipath = "0.1"
once_cell = "1.20"
open = "5.3" open = "5.3"
os_pipe = { version = "1.2", features = ["io_safety"] } os_pipe = { version = "1.2", features = ["io_safety"] }
pathdiff = "0.2" pathdiff = "0.2"

View file

@ -38,7 +38,6 @@ is_executable = { workspace = true }
log = { workspace = true } log = { workspace = true }
miette = { workspace = true, features = ["fancy-no-backtrace"] } miette = { workspace = true, features = ["fancy-no-backtrace"] }
lscolors = { workspace = true, default-features = false, features = ["nu-ansi-term"] } lscolors = { workspace = true, default-features = false, features = ["nu-ansi-term"] }
once_cell = { workspace = true }
percent-encoding = { workspace = true } percent-encoding = { workspace = true }
sysinfo = { workspace = true } sysinfo = { workspace = true }
unicode-segmentation = { workspace = true } unicode-segmentation = { workspace = true }

View file

@ -1358,10 +1358,9 @@ fn run_finaliziation_ansi_sequence(
// Absolute paths with a drive letter, like 'C:', 'D:\', 'E:\foo' // Absolute paths with a drive letter, like 'C:', 'D:\', 'E:\foo'
#[cfg(windows)] #[cfg(windows)]
static DRIVE_PATH_REGEX: once_cell::sync::Lazy<fancy_regex::Regex> = static DRIVE_PATH_REGEX: std::sync::LazyLock<fancy_regex::Regex> = std::sync::LazyLock::new(|| {
once_cell::sync::Lazy::new(|| {
fancy_regex::Regex::new(r"^[a-zA-Z]:[/\\]?").expect("Internal error: regex creation") fancy_regex::Regex::new(r"^[a-zA-Z]:[/\\]?").expect("Internal error: regex creation")
}); });
// A best-effort "does this string look kinda like a path?" function to determine whether to auto-cd // A best-effort "does this string look kinda like a path?" function to determine whether to auto-cd
fn looks_like_path(orig: &str) -> bool { fn looks_like_path(orig: &str) -> bool {

View file

@ -67,7 +67,6 @@ notify-debouncer-full = { workspace = true, default-features = false }
num-format = { workspace = true } num-format = { workspace = true }
num-traits = { workspace = true } num-traits = { workspace = true }
oem_cp = { workspace = true } oem_cp = { workspace = true }
once_cell = { workspace = true }
open = { workspace = true } open = { workspace = true }
os_pipe = { workspace = true } os_pipe = { workspace = true }
pathdiff = { workspace = true } pathdiff = { workspace = true }

View file

@ -1,9 +1,9 @@
use crate::parse_date_from_string; use crate::parse_date_from_string;
use nu_engine::command_prelude::*; use nu_engine::command_prelude::*;
use nu_protocol::PipelineIterator; use nu_protocol::PipelineIterator;
use once_cell::sync::Lazy;
use regex::{Regex, RegexBuilder}; use regex::{Regex, RegexBuilder};
use std::collections::HashSet; use std::collections::HashSet;
use std::sync::LazyLock;
#[derive(Clone)] #[derive(Clone)]
pub struct IntoValue; pub struct IntoValue;
@ -271,8 +271,9 @@ const DATETIME_DMY_PATTERN: &str = r#"(?x)
$ $
"#; "#;
static DATETIME_DMY_RE: Lazy<Regex> = static DATETIME_DMY_RE: LazyLock<Regex> = LazyLock::new(|| {
Lazy::new(|| Regex::new(DATETIME_DMY_PATTERN).expect("datetime_dmy_pattern should be valid")); Regex::new(DATETIME_DMY_PATTERN).expect("datetime_dmy_pattern should be valid")
});
const DATETIME_YMD_PATTERN: &str = r#"(?x) const DATETIME_YMD_PATTERN: &str = r#"(?x)
^ ^
['"]? # optional quotes ['"]? # optional quotes
@ -297,8 +298,9 @@ const DATETIME_YMD_PATTERN: &str = r#"(?x)
['"]? # optional quotes ['"]? # optional quotes
$ $
"#; "#;
static DATETIME_YMD_RE: Lazy<Regex> = static DATETIME_YMD_RE: LazyLock<Regex> = LazyLock::new(|| {
Lazy::new(|| Regex::new(DATETIME_YMD_PATTERN).expect("datetime_ymd_pattern should be valid")); Regex::new(DATETIME_YMD_PATTERN).expect("datetime_ymd_pattern should be valid")
});
//2023-03-24 16:44:17.865147299 -05:00 //2023-03-24 16:44:17.865147299 -05:00
const DATETIME_YMDZ_PATTERN: &str = r#"(?x) const DATETIME_YMDZ_PATTERN: &str = r#"(?x)
^ ^
@ -331,23 +333,24 @@ const DATETIME_YMDZ_PATTERN: &str = r#"(?x)
['"]? # optional quotes ['"]? # optional quotes
$ $
"#; "#;
static DATETIME_YMDZ_RE: Lazy<Regex> = static DATETIME_YMDZ_RE: LazyLock<Regex> = LazyLock::new(|| {
Lazy::new(|| Regex::new(DATETIME_YMDZ_PATTERN).expect("datetime_ymdz_pattern should be valid")); Regex::new(DATETIME_YMDZ_PATTERN).expect("datetime_ymdz_pattern should be valid")
});
static FLOAT_RE: Lazy<Regex> = Lazy::new(|| { static FLOAT_RE: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(r"^\s*[-+]?((\d*\.\d+)([eE][-+]?\d+)?|inf|NaN|(\d+)[eE][-+]?\d+|\d+\.)$") Regex::new(r"^\s*[-+]?((\d*\.\d+)([eE][-+]?\d+)?|inf|NaN|(\d+)[eE][-+]?\d+|\d+\.)$")
.expect("float pattern should be valid") .expect("float pattern should be valid")
}); });
static INTEGER_RE: Lazy<Regex> = static INTEGER_RE: LazyLock<Regex> =
Lazy::new(|| Regex::new(r"^\s*-?(\d+)$").expect("integer pattern should be valid")); LazyLock::new(|| Regex::new(r"^\s*-?(\d+)$").expect("integer pattern should be valid"));
static INTEGER_WITH_DELIMS_RE: Lazy<Regex> = Lazy::new(|| { static INTEGER_WITH_DELIMS_RE: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(r"^\s*-?(\d{1,3}([,_]\d{3})+)$") Regex::new(r"^\s*-?(\d{1,3}([,_]\d{3})+)$")
.expect("integer with delimiters pattern should be valid") .expect("integer with delimiters pattern should be valid")
}); });
static BOOLEAN_RE: Lazy<Regex> = Lazy::new(|| { static BOOLEAN_RE: LazyLock<Regex> = LazyLock::new(|| {
RegexBuilder::new(r"^\s*(true)$|^(false)$") RegexBuilder::new(r"^\s*(true)$|^(false)$")
.case_insensitive(true) .case_insensitive(true)
.build() .build()

View file

@ -1,8 +1,8 @@
use nu_ansi_term::*; use nu_ansi_term::*;
use nu_engine::command_prelude::*; use nu_engine::command_prelude::*;
use nu_protocol::{engine::StateWorkingSet, Signals}; use nu_protocol::{engine::StateWorkingSet, Signals};
use once_cell::sync::Lazy;
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::LazyLock;
#[derive(Clone)] #[derive(Clone)]
pub struct AnsiCommand; pub struct AnsiCommand;
@ -14,7 +14,7 @@ struct AnsiCode {
} }
#[rustfmt::skip] #[rustfmt::skip]
static CODE_LIST: Lazy<Vec<AnsiCode>> = Lazy::new(|| { vec![ static CODE_LIST: LazyLock<Vec<AnsiCode>> = LazyLock::new(|| { vec![
AnsiCode{ short_name: Some("g"), long_name: "green", code: Color::Green.prefix().to_string()}, AnsiCode{ short_name: Some("g"), long_name: "green", code: Color::Green.prefix().to_string()},
AnsiCode{ short_name: Some("gb"), long_name: "green_bold", code: Color::Green.bold().prefix().to_string()}, AnsiCode{ short_name: Some("gb"), long_name: "green_bold", code: Color::Green.bold().prefix().to_string()},
AnsiCode{ short_name: Some("gu"), long_name: "green_underline", code: Color::Green.underline().prefix().to_string()}, AnsiCode{ short_name: Some("gu"), long_name: "green_underline", code: Color::Green.underline().prefix().to_string()},
@ -494,8 +494,8 @@ static CODE_LIST: Lazy<Vec<AnsiCode>> = Lazy::new(|| { vec![
] ]
}); });
static CODE_MAP: Lazy<HashMap<&'static str, &'static str>> = static CODE_MAP: LazyLock<HashMap<&'static str, &'static str>> =
Lazy::new(|| build_ansi_hashmap(&CODE_LIST)); LazyLock::new(|| build_ansi_hashmap(&CODE_LIST));
impl Command for AnsiCommand { impl Command for AnsiCommand {
fn name(&self) -> &str { fn name(&self) -> &str {

View file

@ -1,7 +1,7 @@
use nix::sys::resource::{rlim_t, Resource, RLIM_INFINITY}; use nix::sys::resource::{rlim_t, Resource, RLIM_INFINITY};
use nu_engine::command_prelude::*; use nu_engine::command_prelude::*;
use once_cell::sync::Lazy; use std::sync::LazyLock;
/// An object contains resource related parameters /// An object contains resource related parameters
struct ResourceInfo<'a> { struct ResourceInfo<'a> {
@ -54,7 +54,7 @@ impl<'a> Default for ResourceInfo<'a> {
} }
} }
static RESOURCE_ARRAY: Lazy<Vec<ResourceInfo>> = Lazy::new(|| { static RESOURCE_ARRAY: LazyLock<Vec<ResourceInfo>> = LazyLock::new(|| {
let resources = [ let resources = [
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
( (

View file

@ -2,8 +2,8 @@ use indexmap::{indexmap, IndexMap};
use nu_engine::command_prelude::*; use nu_engine::command_prelude::*;
use nu_protocol::Signals; use nu_protocol::Signals;
use once_cell::sync::Lazy;
use std::collections::HashSet; use std::collections::HashSet;
use std::sync::LazyLock;
// Character used to separate directories in a Path Environment variable on windows is ";" // Character used to separate directories in a Path Environment variable on windows is ";"
#[cfg(target_family = "windows")] #[cfg(target_family = "windows")]
@ -15,7 +15,7 @@ const ENV_PATH_SEPARATOR_CHAR: char = ':';
#[derive(Clone)] #[derive(Clone)]
pub struct Char; pub struct Char;
static CHAR_MAP: Lazy<IndexMap<&'static str, String>> = Lazy::new(|| { static CHAR_MAP: LazyLock<IndexMap<&'static str, String>> = LazyLock::new(|| {
indexmap! { indexmap! {
// These are some regular characters that either can't be used or // These are some regular characters that either can't be used or
// it's just easier to use them like this. // it's just easier to use them like this.
@ -150,7 +150,7 @@ static CHAR_MAP: Lazy<IndexMap<&'static str, String>> = Lazy::new(|| {
} }
}); });
static NO_OUTPUT_CHARS: Lazy<HashSet<&'static str>> = Lazy::new(|| { static NO_OUTPUT_CHARS: LazyLock<HashSet<&'static str>> = LazyLock::new(|| {
[ [
// If the character is in the this set, we don't output it to prevent // If the character is in the this set, we don't output it to prevent
// the broken of `char --list` command table format and alignment. // the broken of `char --list` command table format and alignment.

View file

@ -1,12 +1,12 @@
use nu_engine::command_prelude::*; use nu_engine::command_prelude::*;
use oem_cp::decode_string_complete_table; use oem_cp::decode_string_complete_table;
use once_cell::sync::Lazy;
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::LazyLock;
// create a lazycell of all the code_table "Complete" code pages // create a lazycell of all the code_table "Complete" code pages
// the commented out code pages are "Incomplete", which means they // the commented out code pages are "Incomplete", which means they
// are stored as Option<char> and not &[char; 128] // are stored as Option<char> and not &[char; 128]
static OEM_DECODE: Lazy<HashMap<usize, &[char; 128]>> = Lazy::new(|| { static OEM_DECODE: LazyLock<HashMap<usize, &[char; 128]>> = LazyLock::new(|| {
let mut m = HashMap::new(); let mut m = HashMap::new();
m.insert(437, &oem_cp::code_table::DECODING_TABLE_CP437); m.insert(437, &oem_cp::code_table::DECODING_TABLE_CP437);
// m.insert(720, &oem_cp::code_table::DECODING_TABLE_CP720); // m.insert(720, &oem_cp::code_table::DECODING_TABLE_CP720);

View file

@ -1,5 +1,5 @@
use nu_protocol::{ShellError, Span}; use nu_protocol::{ShellError, Span};
use once_cell::sync::Lazy; use std::sync::LazyLock;
use std::{collections::HashMap, path::Path}; use std::{collections::HashMap, path::Path};
// Attribution: Thanks exa. Most of this file is taken from around here // Attribution: Thanks exa. Most of this file is taken from around here
@ -84,7 +84,7 @@ impl Icons {
// .unwrap_or_default() // .unwrap_or_default()
// } // }
static MAP_BY_NAME: Lazy<HashMap<&'static str, char>> = Lazy::new(|| { static MAP_BY_NAME: LazyLock<HashMap<&'static str, char>> = LazyLock::new(|| {
[ [
(".Trash", '\u{f1f8}'), //  (".Trash", '\u{f1f8}'), // 
(".atom", '\u{e764}'), //  (".atom", '\u{e764}'), // 

View file

@ -30,7 +30,6 @@ log = { workspace = true }
terminal_size = { workspace = true } terminal_size = { workspace = true }
strip-ansi-escapes = { workspace = true } strip-ansi-escapes = { workspace = true }
crossterm = { workspace = true } crossterm = { workspace = true }
once_cell = { workspace = true }
ratatui = { workspace = true } ratatui = { workspace = true }
ansi-str = { workspace = true } ansi-str = { workspace = true }
unicode-width = { workspace = true } unicode-width = { workspace = true }

View file

@ -7,7 +7,7 @@ use nu_protocol::{
Value, Value,
}; };
use once_cell::sync::Lazy; use std::sync::LazyLock;
#[derive(Debug, Default, Clone)] #[derive(Debug, Default, Clone)]
pub struct HelpCmd {} pub struct HelpCmd {}
@ -19,7 +19,7 @@ impl HelpCmd {
} }
} }
static HELP_MESSAGE: Lazy<String> = Lazy::new(|| { static HELP_MESSAGE: LazyLock<String> = LazyLock::new(|| {
let title = nu_ansi_term::Style::new().bold().underline(); let title = nu_ansi_term::Style::new().bold().underline();
let code = nu_ansi_term::Style::new().bold().fg(Color::Blue); let code = nu_ansi_term::Style::new().bold().fg(Color::Blue);

View file

@ -34,7 +34,6 @@ mach2 = { workspace = true }
[target.'cfg(target_os = "windows")'.dependencies] [target.'cfg(target_os = "windows")'.dependencies]
chrono = { workspace = true, default-features = false, features = ["clock"] } chrono = { workspace = true, default-features = false, features = ["clock"] }
ntapi = "0.4" ntapi = "0.4"
once_cell = { workspace = true }
windows = { workspace = true, features = [ windows = { workspace = true, features = [
"Wdk_System_SystemServices", "Wdk_System_SystemServices",
"Wdk_System_Threading", "Wdk_System_Threading",

View file

@ -8,7 +8,6 @@ use libc::c_void;
use ntapi::ntrtl::RTL_USER_PROCESS_PARAMETERS; use ntapi::ntrtl::RTL_USER_PROCESS_PARAMETERS;
use ntapi::ntwow64::{PEB32, RTL_USER_PROCESS_PARAMETERS32}; use ntapi::ntwow64::{PEB32, RTL_USER_PROCESS_PARAMETERS32};
use once_cell::sync::Lazy;
use std::cell::RefCell; use std::cell::RefCell;
use std::collections::HashMap; use std::collections::HashMap;
use std::ffi::OsString; use std::ffi::OsString;
@ -17,6 +16,7 @@ use std::os::windows::ffi::OsStringExt;
use std::path::PathBuf; use std::path::PathBuf;
use std::ptr; use std::ptr;
use std::ptr::null_mut; use std::ptr::null_mut;
use std::sync::LazyLock;
use std::thread; use std::thread;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
@ -694,7 +694,7 @@ unsafe fn get_process_params(
)) ))
} }
static WINDOWS_8_1_OR_NEWER: Lazy<bool> = Lazy::new(|| unsafe { static WINDOWS_8_1_OR_NEWER: LazyLock<bool> = LazyLock::new(|| unsafe {
let mut version_info: OSVERSIONINFOEXW = MaybeUninit::zeroed().assume_init(); let mut version_info: OSVERSIONINFOEXW = MaybeUninit::zeroed().assume_init();
version_info.dwOSVersionInfoSize = std::mem::size_of::<OSVERSIONINFOEXW>() as u32; version_info.dwOSVersionInfoSize = std::mem::size_of::<OSVERSIONINFOEXW>() as u32;

View file

@ -19,7 +19,6 @@ nu-utils = { path = "../nu-utils", version = "0.99.2" }
nu-engine = { path = "../nu-engine", version = "0.99.2" } nu-engine = { path = "../nu-engine", version = "0.99.2" }
nu-color-config = { path = "../nu-color-config", version = "0.99.2" } nu-color-config = { path = "../nu-color-config", version = "0.99.2" }
nu-ansi-term = { workspace = true } nu-ansi-term = { workspace = true }
once_cell = { workspace = true }
fancy-regex = { workspace = true } fancy-regex = { workspace = true }
tabled = { workspace = true, features = ["ansi"], default-features = false } tabled = { workspace = true, features = ["ansi"], default-features = false }
terminal_size = { workspace = true } terminal_size = { workspace = true }

View file

@ -91,12 +91,14 @@ fn colorize_lead_trail_space(
fn colorize_space_one(text: &str, lead: Option<ANSIStr<'_>>, trail: Option<ANSIStr<'_>>) -> String { fn colorize_space_one(text: &str, lead: Option<ANSIStr<'_>>, trail: Option<ANSIStr<'_>>) -> String {
use fancy_regex::Captures; use fancy_regex::Captures;
use fancy_regex::Regex; use fancy_regex::Regex;
use once_cell::sync::Lazy; use std::sync::LazyLock;
static RE_LEADING: Lazy<Regex> = static RE_LEADING: LazyLock<Regex> = LazyLock::new(|| {
Lazy::new(|| Regex::new(r"(?m)(?P<beginsp>^\s+)").expect("error with leading space regex")); Regex::new(r"(?m)(?P<beginsp>^\s+)").expect("error with leading space regex")
static RE_TRAILING: Lazy<Regex> = });
Lazy::new(|| Regex::new(r"(?m)(?P<endsp>\s+$)").expect("error with trailing space regex")); static RE_TRAILING: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(r"(?m)(?P<endsp>\s+$)").expect("error with trailing space regex")
});
let mut buf = text.to_owned(); let mut buf = text.to_owned();

View file

@ -21,7 +21,6 @@ fancy-regex = { workspace = true }
lscolors = { workspace = true, default-features = false, features = ["nu-ansi-term"] } lscolors = { workspace = true, default-features = false, features = ["nu-ansi-term"] }
log = { workspace = true } log = { workspace = true }
num-format = { workspace = true } num-format = { workspace = true }
once_cell = { workspace = true }
strip-ansi-escapes = { workspace = true } strip-ansi-escapes = { workspace = true }
serde = { workspace = true } serde = { workspace = true }
sys-locale = "0.3" sys-locale = "0.3"

View file

@ -1,12 +1,12 @@
use fancy_regex::Regex; use fancy_regex::Regex;
use once_cell::sync::Lazy; use std::sync::LazyLock;
// This hits, in order: // This hits, in order:
// • Any character of []:`{}#'";()|$, // • Any character of []:`{}#'";()|$,
// • Any digit (\d) // • Any digit (\d)
// • Any whitespace (\s) // • Any whitespace (\s)
// • Case-insensitive sign-insensitive float "keywords" inf, infinity and nan. // • Case-insensitive sign-insensitive float "keywords" inf, infinity and nan.
static NEEDS_QUOTING_REGEX: Lazy<Regex> = Lazy::new(|| { static NEEDS_QUOTING_REGEX: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(r#"[\[\]:`\{\}#'";\(\)\|\$,\d\s]|(?i)^[+\-]?(inf(inity)?|nan)$"#) Regex::new(r#"[\[\]:`\{\}#'";\(\)\|\$,\d\s]|(?i)^[+\-]?(inf(inity)?|nan)$"#)
.expect("internal error: NEEDS_QUOTING_REGEX didn't compile") .expect("internal error: NEEDS_QUOTING_REGEX didn't compile")
}); });