From 2c07f5fa6cc867ef9e52816a7bbc1ebc46d33c6d Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 4 Jun 2024 14:23:46 -0400 Subject: [PATCH] lib: Drop our once_cell usage The cool kids are using the `std` version for this now. Signed-off-by: Colin Walters --- Cargo.lock | 1 - lib/Cargo.toml | 1 - lib/src/blockdev.rs | 7 ++++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d1bbcf461..1c6360273 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -184,7 +184,6 @@ dependencies = [ "liboverdrop", "libsystemd", "nix 0.28.0", - "once_cell", "openssl", "ostree-ext", "regex", diff --git a/lib/Cargo.toml b/lib/Cargo.toml index f9b3eeb76..4754cf24b 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -28,7 +28,6 @@ indicatif = "0.17.8" libc = "^0.2.154" liboverdrop = "0.1.0" libsystemd = "0.7" -once_cell = "1.19" openssl = "^0.10.64" # TODO drop this in favor of rustix nix = { version = "0.28", features = ["ioctl", "sched"] } diff --git a/lib/src/blockdev.rs b/lib/src/blockdev.rs index fc7024e1c..f8facdf78 100644 --- a/lib/src/blockdev.rs +++ b/lib/src/blockdev.rs @@ -4,7 +4,6 @@ use anyhow::{anyhow, Context, Result}; use camino::{Utf8Path, Utf8PathBuf}; use fn_error_context::context; use nix::errno::Errno; -use once_cell::sync::Lazy; use regex::Regex; use serde::Deserialize; use std::collections::HashMap; @@ -13,6 +12,7 @@ use std::fs::File; use std::os::unix::io::AsRawFd; use std::path::Path; use std::process::Command; +use std::sync::OnceLock; #[derive(Debug, Deserialize)] struct DevicesOutput { @@ -185,9 +185,10 @@ pub(crate) fn reread_partition_table(file: &mut File, retry: bool) -> Result<()> /// Parse key-value pairs from lsblk --pairs. /// Newer versions of lsblk support JSON but the one in CentOS 7 doesn't. fn split_lsblk_line(line: &str) -> HashMap { - static REGEX: Lazy = Lazy::new(|| Regex::new(r#"([A-Z-_]+)="([^"]+)""#).unwrap()); + static REGEX: OnceLock = OnceLock::new(); + let regex = REGEX.get_or_init(|| Regex::new(r#"([A-Z-_]+)="([^"]+)""#).unwrap()); let mut fields: HashMap = HashMap::new(); - for cap in REGEX.captures_iter(line) { + for cap in regex.captures_iter(line) { fields.insert(cap[1].to_string(), cap[2].to_string()); } fields