mirror of
https://github.com/nushell/nushell
synced 2024-12-25 12:33:17 +00:00
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:
parent
74bd0e32cc
commit
e104bccfb9
19 changed files with 44 additions and 53 deletions
6
Cargo.lock
generated
6
Cargo.lock
generated
|
@ -3020,7 +3020,6 @@ dependencies = [
|
|||
"nu-protocol",
|
||||
"nu-test-support",
|
||||
"nu-utils",
|
||||
"once_cell",
|
||||
"percent-encoding",
|
||||
"reedline",
|
||||
"rstest",
|
||||
|
@ -3164,7 +3163,6 @@ dependencies = [
|
|||
"num-traits",
|
||||
"nuon",
|
||||
"oem_cp",
|
||||
"once_cell",
|
||||
"open",
|
||||
"os_pipe",
|
||||
"pathdiff",
|
||||
|
@ -3257,7 +3255,6 @@ dependencies = [
|
|||
"nu-protocol",
|
||||
"nu-table",
|
||||
"nu-utils",
|
||||
"once_cell",
|
||||
"ratatui",
|
||||
"strip-ansi-escapes",
|
||||
"terminal_size",
|
||||
|
@ -3477,7 +3474,6 @@ dependencies = [
|
|||
"mach2",
|
||||
"nix 0.29.0",
|
||||
"ntapi",
|
||||
"once_cell",
|
||||
"procfs",
|
||||
"sysinfo 0.32.0",
|
||||
"windows",
|
||||
|
@ -3493,7 +3489,6 @@ dependencies = [
|
|||
"nu-engine",
|
||||
"nu-protocol",
|
||||
"nu-utils",
|
||||
"once_cell",
|
||||
"tabled",
|
||||
"terminal_size",
|
||||
]
|
||||
|
@ -3528,7 +3523,6 @@ dependencies = [
|
|||
"lscolors",
|
||||
"nix 0.29.0",
|
||||
"num-format",
|
||||
"once_cell",
|
||||
"serde",
|
||||
"strip-ansi-escapes",
|
||||
"sys-locale",
|
||||
|
|
|
@ -119,7 +119,6 @@ num-format = "0.4"
|
|||
num-traits = "0.2"
|
||||
oem_cp = "2.0.0"
|
||||
omnipath = "0.1"
|
||||
once_cell = "1.20"
|
||||
open = "5.3"
|
||||
os_pipe = { version = "1.2", features = ["io_safety"] }
|
||||
pathdiff = "0.2"
|
||||
|
|
|
@ -38,7 +38,6 @@ is_executable = { workspace = true }
|
|||
log = { workspace = true }
|
||||
miette = { workspace = true, features = ["fancy-no-backtrace"] }
|
||||
lscolors = { workspace = true, default-features = false, features = ["nu-ansi-term"] }
|
||||
once_cell = { workspace = true }
|
||||
percent-encoding = { workspace = true }
|
||||
sysinfo = { workspace = true }
|
||||
unicode-segmentation = { workspace = true }
|
||||
|
|
|
@ -1358,10 +1358,9 @@ fn run_finaliziation_ansi_sequence(
|
|||
|
||||
// Absolute paths with a drive letter, like 'C:', 'D:\', 'E:\foo'
|
||||
#[cfg(windows)]
|
||||
static DRIVE_PATH_REGEX: once_cell::sync::Lazy<fancy_regex::Regex> =
|
||||
once_cell::sync::Lazy::new(|| {
|
||||
fancy_regex::Regex::new(r"^[a-zA-Z]:[/\\]?").expect("Internal error: regex creation")
|
||||
});
|
||||
static DRIVE_PATH_REGEX: std::sync::LazyLock<fancy_regex::Regex> = std::sync::LazyLock::new(|| {
|
||||
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
|
||||
fn looks_like_path(orig: &str) -> bool {
|
||||
|
|
|
@ -67,7 +67,6 @@ notify-debouncer-full = { workspace = true, default-features = false }
|
|||
num-format = { workspace = true }
|
||||
num-traits = { workspace = true }
|
||||
oem_cp = { workspace = true }
|
||||
once_cell = { workspace = true }
|
||||
open = { workspace = true }
|
||||
os_pipe = { workspace = true }
|
||||
pathdiff = { workspace = true }
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use crate::parse_date_from_string;
|
||||
use nu_engine::command_prelude::*;
|
||||
use nu_protocol::PipelineIterator;
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::{Regex, RegexBuilder};
|
||||
use std::collections::HashSet;
|
||||
use std::sync::LazyLock;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct IntoValue;
|
||||
|
@ -271,8 +271,9 @@ const DATETIME_DMY_PATTERN: &str = r#"(?x)
|
|||
$
|
||||
"#;
|
||||
|
||||
static DATETIME_DMY_RE: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(DATETIME_DMY_PATTERN).expect("datetime_dmy_pattern should be valid"));
|
||||
static DATETIME_DMY_RE: LazyLock<Regex> = LazyLock::new(|| {
|
||||
Regex::new(DATETIME_DMY_PATTERN).expect("datetime_dmy_pattern should be valid")
|
||||
});
|
||||
const DATETIME_YMD_PATTERN: &str = r#"(?x)
|
||||
^
|
||||
['"]? # optional quotes
|
||||
|
@ -297,8 +298,9 @@ const DATETIME_YMD_PATTERN: &str = r#"(?x)
|
|||
['"]? # optional quotes
|
||||
$
|
||||
"#;
|
||||
static DATETIME_YMD_RE: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(DATETIME_YMD_PATTERN).expect("datetime_ymd_pattern should be valid"));
|
||||
static DATETIME_YMD_RE: LazyLock<Regex> = LazyLock::new(|| {
|
||||
Regex::new(DATETIME_YMD_PATTERN).expect("datetime_ymd_pattern should be valid")
|
||||
});
|
||||
//2023-03-24 16:44:17.865147299 -05:00
|
||||
const DATETIME_YMDZ_PATTERN: &str = r#"(?x)
|
||||
^
|
||||
|
@ -331,23 +333,24 @@ const DATETIME_YMDZ_PATTERN: &str = r#"(?x)
|
|||
['"]? # optional quotes
|
||||
$
|
||||
"#;
|
||||
static DATETIME_YMDZ_RE: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(DATETIME_YMDZ_PATTERN).expect("datetime_ymdz_pattern should be valid"));
|
||||
static DATETIME_YMDZ_RE: LazyLock<Regex> = LazyLock::new(|| {
|
||||
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+\.)$")
|
||||
.expect("float pattern should be valid")
|
||||
});
|
||||
|
||||
static INTEGER_RE: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r"^\s*-?(\d+)$").expect("integer pattern should be valid"));
|
||||
static INTEGER_RE: LazyLock<Regex> =
|
||||
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})+)$")
|
||||
.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)$")
|
||||
.case_insensitive(true)
|
||||
.build()
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use nu_ansi_term::*;
|
||||
use nu_engine::command_prelude::*;
|
||||
use nu_protocol::{engine::StateWorkingSet, Signals};
|
||||
use once_cell::sync::Lazy;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::LazyLock;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct AnsiCommand;
|
||||
|
@ -14,7 +14,7 @@ struct AnsiCode {
|
|||
}
|
||||
|
||||
#[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("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()},
|
||||
|
@ -494,8 +494,8 @@ static CODE_LIST: Lazy<Vec<AnsiCode>> = Lazy::new(|| { vec![
|
|||
]
|
||||
});
|
||||
|
||||
static CODE_MAP: Lazy<HashMap<&'static str, &'static str>> =
|
||||
Lazy::new(|| build_ansi_hashmap(&CODE_LIST));
|
||||
static CODE_MAP: LazyLock<HashMap<&'static str, &'static str>> =
|
||||
LazyLock::new(|| build_ansi_hashmap(&CODE_LIST));
|
||||
|
||||
impl Command for AnsiCommand {
|
||||
fn name(&self) -> &str {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use nix::sys::resource::{rlim_t, Resource, RLIM_INFINITY};
|
||||
use nu_engine::command_prelude::*;
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
use std::sync::LazyLock;
|
||||
|
||||
/// An object contains resource related parameters
|
||||
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 = [
|
||||
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
|
||||
(
|
||||
|
|
|
@ -2,8 +2,8 @@ use indexmap::{indexmap, IndexMap};
|
|||
use nu_engine::command_prelude::*;
|
||||
|
||||
use nu_protocol::Signals;
|
||||
use once_cell::sync::Lazy;
|
||||
use std::collections::HashSet;
|
||||
use std::sync::LazyLock;
|
||||
|
||||
// Character used to separate directories in a Path Environment variable on windows is ";"
|
||||
#[cfg(target_family = "windows")]
|
||||
|
@ -15,7 +15,7 @@ const ENV_PATH_SEPARATOR_CHAR: char = ':';
|
|||
#[derive(Clone)]
|
||||
pub struct Char;
|
||||
|
||||
static CHAR_MAP: Lazy<IndexMap<&'static str, String>> = Lazy::new(|| {
|
||||
static CHAR_MAP: LazyLock<IndexMap<&'static str, String>> = LazyLock::new(|| {
|
||||
indexmap! {
|
||||
// These are some regular characters that either can't be used or
|
||||
// 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
|
||||
// the broken of `char --list` command table format and alignment.
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
use nu_engine::command_prelude::*;
|
||||
use oem_cp::decode_string_complete_table;
|
||||
use once_cell::sync::Lazy;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::LazyLock;
|
||||
|
||||
// create a lazycell of all the code_table "Complete" code pages
|
||||
// the commented out code pages are "Incomplete", which means they
|
||||
// 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();
|
||||
m.insert(437, &oem_cp::code_table::DECODING_TABLE_CP437);
|
||||
// m.insert(720, &oem_cp::code_table::DECODING_TABLE_CP720);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use nu_protocol::{ShellError, Span};
|
||||
use once_cell::sync::Lazy;
|
||||
use std::sync::LazyLock;
|
||||
use std::{collections::HashMap, path::Path};
|
||||
|
||||
// Attribution: Thanks exa. Most of this file is taken from around here
|
||||
|
@ -84,7 +84,7 @@ impl Icons {
|
|||
// .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}'), //
|
||||
(".atom", '\u{e764}'), //
|
||||
|
|
|
@ -30,7 +30,6 @@ log = { workspace = true }
|
|||
terminal_size = { workspace = true }
|
||||
strip-ansi-escapes = { workspace = true }
|
||||
crossterm = { workspace = true }
|
||||
once_cell = { workspace = true }
|
||||
ratatui = { workspace = true }
|
||||
ansi-str = { workspace = true }
|
||||
unicode-width = { workspace = true }
|
||||
|
|
|
@ -7,7 +7,7 @@ use nu_protocol::{
|
|||
Value,
|
||||
};
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
use std::sync::LazyLock;
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
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 code = nu_ansi_term::Style::new().bold().fg(Color::Blue);
|
||||
|
||||
|
|
|
@ -34,7 +34,6 @@ mach2 = { workspace = true }
|
|||
[target.'cfg(target_os = "windows")'.dependencies]
|
||||
chrono = { workspace = true, default-features = false, features = ["clock"] }
|
||||
ntapi = "0.4"
|
||||
once_cell = { workspace = true }
|
||||
windows = { workspace = true, features = [
|
||||
"Wdk_System_SystemServices",
|
||||
"Wdk_System_Threading",
|
||||
|
|
|
@ -8,7 +8,6 @@ use libc::c_void;
|
|||
use ntapi::ntrtl::RTL_USER_PROCESS_PARAMETERS;
|
||||
use ntapi::ntwow64::{PEB32, RTL_USER_PROCESS_PARAMETERS32};
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
use std::ffi::OsString;
|
||||
|
@ -17,6 +16,7 @@ use std::os::windows::ffi::OsStringExt;
|
|||
use std::path::PathBuf;
|
||||
use std::ptr;
|
||||
use std::ptr::null_mut;
|
||||
use std::sync::LazyLock;
|
||||
use std::thread;
|
||||
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();
|
||||
|
||||
version_info.dwOSVersionInfoSize = std::mem::size_of::<OSVERSIONINFOEXW>() as u32;
|
||||
|
|
|
@ -19,7 +19,6 @@ nu-utils = { path = "../nu-utils", 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-ansi-term = { workspace = true }
|
||||
once_cell = { workspace = true }
|
||||
fancy-regex = { workspace = true }
|
||||
tabled = { workspace = true, features = ["ansi"], default-features = false }
|
||||
terminal_size = { workspace = true }
|
||||
|
|
|
@ -91,12 +91,14 @@ fn colorize_lead_trail_space(
|
|||
fn colorize_space_one(text: &str, lead: Option<ANSIStr<'_>>, trail: Option<ANSIStr<'_>>) -> String {
|
||||
use fancy_regex::Captures;
|
||||
use fancy_regex::Regex;
|
||||
use once_cell::sync::Lazy;
|
||||
use std::sync::LazyLock;
|
||||
|
||||
static RE_LEADING: Lazy<Regex> =
|
||||
Lazy::new(|| 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_LEADING: LazyLock<Regex> = LazyLock::new(|| {
|
||||
Regex::new(r"(?m)(?P<beginsp>^\s+)").expect("error with leading 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();
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ fancy-regex = { workspace = true }
|
|||
lscolors = { workspace = true, default-features = false, features = ["nu-ansi-term"] }
|
||||
log = { workspace = true }
|
||||
num-format = { workspace = true }
|
||||
once_cell = { workspace = true }
|
||||
strip-ansi-escapes = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
sys-locale = "0.3"
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
use fancy_regex::Regex;
|
||||
use once_cell::sync::Lazy;
|
||||
use std::sync::LazyLock;
|
||||
|
||||
// This hits, in order:
|
||||
// • Any character of []:`{}#'";()|$,
|
||||
// • Any digit (\d)
|
||||
// • Any whitespace (\s)
|
||||
// • 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)$"#)
|
||||
.expect("internal error: NEEDS_QUOTING_REGEX didn't compile")
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue