Merge pull request #58 from MarijnS95/once-cell

Replace ancient `lazy_static` crate with `once_cell`
This commit is contained in:
Harry Fei
2022-06-12 20:54:40 +08:00
committed by GitHub
3 changed files with 22 additions and 24 deletions
+1 -1
View File
@@ -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
View File
@@ -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()
-4
View File
@@ -14,10 +14,6 @@
//!
//! ```
#[cfg(windows)]
#[macro_use]
extern crate lazy_static;
mod checker;
mod error;
mod finder;