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
19 changed files with 44 additions and 53 deletions

View File

@ -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 }

View File

@ -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()

View File

@ -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 {

View File

@ -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"))]
(

View File

@ -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.

View File

@ -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);

View File

@ -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}'), // 