mirror of
https://github.com/openharmony/third_party_rust_which-rs.git
synced 2026-07-01 21:14:07 -04:00
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
This commit is contained in:
+1
-1
@@ -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"
|
||||
|
||||
+21
-19
@@ -151,29 +151,31 @@ impl Finder {
|
||||
where
|
||||
P: IntoIterator<Item = PathBuf>,
|
||||
{
|
||||
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<String> =
|
||||
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<Vec<String>> = 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()
|
||||
|
||||
@@ -14,10 +14,6 @@
|
||||
//!
|
||||
//! ```
|
||||
|
||||
#[cfg(windows)]
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
|
||||
mod checker;
|
||||
mod error;
|
||||
mod finder;
|
||||
|
||||
Reference in New Issue
Block a user