From 30941ed26db622921c7e9ca50dea47e70d7be977 Mon Sep 17 00:00:00 2001 From: Stuart Reilly Date: Thu, 12 Jun 2025 07:32:29 +0100 Subject: [PATCH] Drop lazy_static (#1168) Co-authored-by: Stuart Reilly --- Cargo.lock | 1 - Cargo.toml | 1 - src/steps/generic.rs | 24 ++++++++++-------------- src/steps/os/unix.rs | 23 ++++++++++------------- src/terminal.rs | 7 ++----- 5 files changed, 22 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cbcdbdbb..b2c071c2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2886,7 +2886,6 @@ dependencies = [ "glob", "home", "jetbrains-toolbox-updater", - "lazy_static", "merge", "nix 0.29.0", "notify-rust", diff --git a/Cargo.toml b/Cargo.toml index 25b2f4b3..9811afdb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,6 @@ clap_complete = "~4.5" clap_mangen = "~0.2" walkdir = "~2.5" console = "~0.15" -lazy_static = "~1.4" chrono = "~0.4" glob = "~0.3" strum = { version = "~0.26", features = ["derive"] } diff --git a/src/steps/generic.rs b/src/steps/generic.rs index 15bbd991..809b16f3 100644 --- a/src/steps/generic.rs +++ b/src/steps/generic.rs @@ -1,17 +1,16 @@ -use std::ffi::OsString; -use std::path::PathBuf; -use std::process::Command; -use std::{env, path::Path}; -use std::{fs, io::Write}; - use color_eyre::eyre::eyre; use color_eyre::eyre::Context; use color_eyre::eyre::Result; use jetbrains_toolbox_updater::{find_jetbrains_toolbox, update_jetbrains_toolbox, FindError}; -use lazy_static::lazy_static; use regex::bytes::Regex; use rust_i18n::t; use semver::Version; +use std::ffi::OsString; +use std::path::PathBuf; +use std::process::Command; +use std::sync::LazyLock; +use std::{env, path::Path}; +use std::{fs, io::Write}; use tempfile::tempfile_in; use tracing::{debug, error}; @@ -1233,9 +1232,8 @@ pub fn run_poetry(ctx: &ExecutionContext) -> Result<()> { use std::ffi::OsStr; use std::os::unix::ffi::OsStrExt; - lazy_static! { - static ref SHEBANG_REGEX: Regex = Regex::new(r"^#![ \t]*([^ \t\n]+)(?:[ \t]+([^\n]+)?)?").unwrap(); - } + static SHEBANG_REGEX: LazyLock = + LazyLock::new(|| Regex::new(r"^#![ \t]*([^ \t\n]+)(?:[ \t]+([^\n]+)?)?").unwrap()); let script = fs::read(poetry)?; if let Some(c) = SHEBANG_REGEX.captures(&script) { @@ -1254,10 +1252,8 @@ pub fn run_poetry(ctx: &ExecutionContext) -> Result<()> { use std::str; - lazy_static! { - static ref SHEBANG_REGEX: Regex = - Regex::new(r#"^#![ \t]*(?:"([^"\n]+)"|([^" \t\n]+))(?:[ \t]+([^\n]+)?)?"#).unwrap(); - } + static SHEBANG_REGEX: LazyLock = + LazyLock::new(|| Regex::new(r#"^#![ \t]*(?:"([^"\n]+)"|([^" \t\n]+))(?:[ \t]+([^\n]+)?)?"#).unwrap()); let data = fs::read(poetry)?; diff --git a/src/steps/os/unix.rs b/src/steps/os/unix.rs index f883122e..fc54b7d1 100644 --- a/src/steps/os/unix.rs +++ b/src/steps/os/unix.rs @@ -1,11 +1,3 @@ -use std::ffi::OsStr; -use std::fs; -use std::os::unix::fs::MetadataExt; -use std::path::Component; -use std::path::PathBuf; -use std::process::Command; -use std::{env::var, path::Path}; - use crate::command::CommandExt; use crate::{output_changed_message, Step, HOME_DIR}; use color_eyre::eyre::eyre; @@ -13,12 +5,19 @@ use color_eyre::eyre::Context; use color_eyre::eyre::Result; use home; use ini::Ini; -use lazy_static::lazy_static; #[cfg(target_os = "linux")] use nix::unistd::Uid; use regex::Regex; use rust_i18n::t; use semver::Version; +use std::ffi::OsStr; +use std::fs; +use std::os::unix::fs::MetadataExt; +use std::path::Component; +use std::path::PathBuf; +use std::process::Command; +use std::sync::LazyLock; +use std::{env::var, path::Path}; use tracing::debug; #[cfg(target_os = "linux")] @@ -461,10 +460,8 @@ pub fn run_nix(ctx: &ExecutionContext) -> Result<()> { "`nix --version` output" ); - lazy_static! { - static ref NIX_VERSION_REGEX: Regex = - Regex::new(r"^nix \([^)]*\) ([0-9.]+)").expect("Nix version regex always compiles"); - } + static NIX_VERSION_REGEX: LazyLock = + LazyLock::new(|| Regex::new(r"^nix \([^)]*\) ([0-9.]+)").expect("Nix version regex always compiles")); if get_version_cmd_first_line_stdout.is_empty() { return Err(eyre!("`nix --version` output was empty")); diff --git a/src/terminal.rs b/src/terminal.rs index 59257d44..64e41c32 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -2,14 +2,13 @@ use std::cmp::{max, min}; use std::env; use std::io::{self, Write}; use std::process::Command; -use std::sync::Mutex; +use std::sync::{LazyLock, Mutex}; use std::time::Duration; use chrono::{Local, Timelike}; use color_eyre::eyre; use color_eyre::eyre::Context; use console::{style, Key, Term}; -use lazy_static::lazy_static; use notify_rust::{Notification, Timeout}; use rust_i18n::t; use tracing::{debug, error}; @@ -19,9 +18,7 @@ use which_crate::which; use crate::command::CommandExt; use crate::report::StepResult; -lazy_static! { - static ref TERMINAL: Mutex = Mutex::new(Terminal::new()); -} +static TERMINAL: LazyLock> = LazyLock::new(|| Mutex::new(Terminal::new())); #[cfg(unix)] pub fn shell() -> String {