From 9161cae51e4d0148ea59f55bfbe31649860c3bef Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Sat, 11 Jun 2022 19:47:11 +0200 Subject: [PATCH] Replace ancient `lazy_static` crate with `once_cell` Piggybacking on the [motivation in winit]: `lazy_static!` is a macro whereas `once_cell` achieves the same using generics. Its implementation has also been [proposed for inclusion in `std`], making it easier to switch to a standardized version if/when that happens. The author of that winit PR is making this change to many more crates, slowly turning the scales in favour of `once_cell` in most dependency trees. Furthermore `lazy_static` hasn't published any updates for 3 years. See also [the `once_cell` F.A.Q.]. [motivation in winit]: https://github.com/rust-windowing/winit/pull/2313 [proposed for inclusion in `std`]: https://github.com/rust-lang/rust/issues/74465 [the `once_cell` F.A.Q.]: https://docs.rs/once_cell/latest/once_cell/#faq --- Cargo.toml | 2 +- src/finder.rs | 40 +++++++++++++++++++++------------------- src/lib.rs | 4 ---- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index dccbdb4..7fe5f05 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ libc = "0.2.121" regex = { version = "1.5.5", optional = true } [target.'cfg(windows)'.dependencies] -lazy_static = "1.4.0" +once_cell = "1" [dev-dependencies] tempfile = "3.3.0" diff --git a/src/finder.rs b/src/finder.rs index f08d698..4c5956d 100644 --- a/src/finder.rs +++ b/src/finder.rs @@ -151,29 +151,31 @@ impl Finder { where P: IntoIterator, { + use once_cell::sync::Lazy; + // Sample %PATHEXT%: .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC // PATH_EXTENSIONS is then [".COM", ".EXE", ".BAT", …]. // (In one use of PATH_EXTENSIONS we skip the dot, but in the other we need it; // hence its retention.) - lazy_static! { - static ref PATH_EXTENSIONS: Vec = - env::var("PATHEXT") - .map(|pathext| { - pathext.split(';') - .filter_map(|s| { - if s.as_bytes().first() == Some(&b'.') { - Some(s.to_owned()) - } else { - // Invalid segment; just ignore it. - None - } - }) - .collect() - }) - // PATHEXT not being set or not being a proper Unicode string is exceedingly - // improbable and would probably break Windows badly. Still, don't crash: - .unwrap_or_default(); - } + static PATH_EXTENSIONS: Lazy> = Lazy::new(|| { + env::var("PATHEXT") + .map(|pathext| { + pathext + .split(';') + .filter_map(|s| { + if s.as_bytes().first() == Some(&b'.') { + Some(s.to_owned()) + } else { + // Invalid segment; just ignore it. + None + } + }) + .collect() + }) + // PATHEXT not being set or not being a proper Unicode string is exceedingly + // improbable and would probably break Windows badly. Still, don't crash: + .unwrap_or_default() + }); paths .into_iter() diff --git a/src/lib.rs b/src/lib.rs index 86d1918..b9026ff 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,10 +14,6 @@ //! //! ``` -#[cfg(windows)] -#[macro_use] -extern crate lazy_static; - mod checker; mod error; mod finder;