From d4c0c110ad635150ce05c4e86eb10373194f8925 Mon Sep 17 00:00:00 2001 From: yozhgoor Date: Sat, 7 Dec 2024 06:53:26 +0100 Subject: [PATCH 1/4] Change `once_cell::Lazy` to `std::cell::LazyCell` --- Cargo.lock | 3 +-- Cargo.toml | 1 - src/dependency.rs | 8 +++----- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a1a8207..c8b03e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "ahash" @@ -206,7 +206,6 @@ dependencies = [ "env_logger", "libc", "log", - "once_cell", "regex", "serde", "tempfile", diff --git a/Cargo.toml b/Cargo.toml index 4a2f650..56df435 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,6 @@ serde = { version = "1", features = ["derive"] } tempfile = "3.10" toml = "0.8" regex = "1.10" -once_cell = "1.19" [target.'cfg(unix)'.dependencies] libc = "0.2" diff --git a/src/dependency.rs b/src/dependency.rs index adfece2..039edf0 100644 --- a/src/dependency.rs +++ b/src/dependency.rs @@ -1,6 +1,6 @@ use anyhow::{bail, Result}; -use once_cell::sync::Lazy; use regex::Regex; +use std::cell::LazyCell; #[derive(Debug, PartialEq, Eq, Clone)] pub enum Dependency { @@ -19,14 +19,12 @@ pub enum Dependency { } pub fn parse_dependency(s: &str) -> Result { - // This will change when `std::lazy` is released. - // See https://github.com/rust-lang/rust/issues/74465. - static RE: Lazy = Lazy::new(|| { + let re: LazyCell = LazyCell::new(|| { Regex::new(r"^((?P[^+=/]+)=)?(?P((?P\w+://([^:@]+(:[^@]+)?@)?[^#+]*?(?P/[^#+/]+)?)(#branch=(?P[^+]+)|#rev=(?P[^+]+))?)|[^+]+)?(?P(\+[^+]+)*)$") .unwrap() }); - match RE.captures(s) { + match re.captures(s) { Some(caps) => { let features = caps .name("features") From 62fcdd136551347c23228803a94e7b30962f49a2 Mon Sep 17 00:00:00 2001 From: yozhgoor Date: Sat, 7 Dec 2024 07:12:09 +0100 Subject: [PATCH 2/4] Leave it as `static` --- src/dependency.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dependency.rs b/src/dependency.rs index 039edf0..cd17996 100644 --- a/src/dependency.rs +++ b/src/dependency.rs @@ -19,12 +19,12 @@ pub enum Dependency { } pub fn parse_dependency(s: &str) -> Result { - let re: LazyCell = LazyCell::new(|| { + static RE: LazyCell = LazyCell::new(|| { Regex::new(r"^((?P[^+=/]+)=)?(?P((?P\w+://([^:@]+(:[^@]+)?@)?[^#+]*?(?P/[^#+/]+)?)(#branch=(?P[^+]+)|#rev=(?P[^+]+))?)|[^+]+)?(?P(\+[^+]+)*)$") .unwrap() }); - match re.captures(s) { + match RE.captures(s) { Some(caps) => { let features = caps .name("features") From bb974a5eba488b143baf95d107b56182f4fb702f Mon Sep 17 00:00:00 2001 From: yozhgoor Date: Sat, 7 Dec 2024 07:15:23 +0100 Subject: [PATCH 3/4] Use `std::sync::LazyLock` instead --- src/dependency.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dependency.rs b/src/dependency.rs index cd17996..69a54c9 100644 --- a/src/dependency.rs +++ b/src/dependency.rs @@ -1,6 +1,6 @@ use anyhow::{bail, Result}; use regex::Regex; -use std::cell::LazyCell; +use std::sync::LazyLock; #[derive(Debug, PartialEq, Eq, Clone)] pub enum Dependency { @@ -19,7 +19,7 @@ pub enum Dependency { } pub fn parse_dependency(s: &str) -> Result { - static RE: LazyCell = LazyCell::new(|| { + static RE: LazyLock = LazyLock::new(|| { Regex::new(r"^((?P[^+=/]+)=)?(?P((?P\w+://([^:@]+(:[^@]+)?@)?[^#+]*?(?P/[^#+/]+)?)(#branch=(?P[^+]+)|#rev=(?P[^+]+))?)|[^+]+)?(?P(\+[^+]+)*)$") .unwrap() }); From 3d42ca343963a7ebba21183f054805a38a7719b2 Mon Sep 17 00:00:00 2001 From: yozhgoor Date: Sat, 7 Dec 2024 08:24:25 +0100 Subject: [PATCH 4/4] Change `unwrap` to `expect` --- src/dependency.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dependency.rs b/src/dependency.rs index 69a54c9..524d528 100644 --- a/src/dependency.rs +++ b/src/dependency.rs @@ -21,7 +21,7 @@ pub enum Dependency { pub fn parse_dependency(s: &str) -> Result { static RE: LazyLock = LazyLock::new(|| { Regex::new(r"^((?P[^+=/]+)=)?(?P((?P\w+://([^:@]+(:[^@]+)?@)?[^#+]*?(?P/[^#+/]+)?)(#branch=(?P[^+]+)|#rev=(?P[^+]+))?)|[^+]+)?(?P(\+[^+]+)*)$") - .unwrap() + .expect("dependency's regex must be compiled") }); match RE.captures(s) {