Use once_cell instead of lazy_static

once_cell can do what lazy_static does and more, so replace lazy_static with
once_cell.

See https://docs.rs/once_cell/1.8.0/once_cell/#general-purpose-lazy-evaluation
This commit is contained in:
Martin Nordholts 2021-11-22 21:10:17 +01:00
parent dd0925a946
commit 5519f9c716
4 changed files with 15 additions and 21 deletions

1
Cargo.lock generated
View File

@ -101,7 +101,6 @@ dependencies = [
"git2",
"globset",
"grep-cli",
"lazy_static",
"nix",
"once_cell",
"path_abs",

View File

@ -27,7 +27,6 @@ minimal-application = [
"atty",
"clap",
"dirs-next",
"lazy_static",
"paging",
"regex-onig",
"wild",
@ -48,7 +47,6 @@ ansi_colours = "^1.0"
bincode = "1.0"
console = "0.15.0"
flate2 = "1.0"
lazy_static = { version = "1.4", optional = true }
once_cell = "1.8"
thiserror = "1.0"
wild = { version = "2.0", optional = true }

View File

@ -1,21 +1,20 @@
use clap::{crate_name, crate_version, App as ClapApp, AppSettings, Arg, ArgGroup, SubCommand};
use once_cell::sync::Lazy;
use std::env;
use std::path::Path;
lazy_static::lazy_static! {
static ref VERSION: String = {
#[cfg(feature = "bugreport")]
let git_version = bugreport::git_version!(fallback = "");
#[cfg(not(feature = "bugreport"))]
let git_version = "";
static VERSION: Lazy<String> = Lazy::new(|| {
#[cfg(feature = "bugreport")]
let git_version = bugreport::git_version!(fallback = "");
#[cfg(not(feature = "bugreport"))]
let git_version = "";
if git_version.is_empty() {
crate_version!().to_string()
} else {
format!("{} ({})", crate_version!(), git_version)
}
};
}
if git_version.is_empty() {
crate_version!().to_string()
} else {
format!("{} ({})", crate_version!(), git_version)
}
});
pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
let clap_color_setting = if interactive_output && env::var_os("NO_COLOR").is_none() {

View File

@ -1,7 +1,7 @@
use std::env;
use std::path::{Path, PathBuf};
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
/// Wrapper for 'dirs' that treats MacOS more like Linux, by following the XDG specification.
/// The `XDG_CACHE_HOME` environment variable is checked first. `BAT_CONFIG_DIR`
@ -68,7 +68,5 @@ impl BatProjectDirs {
}
}
lazy_static! {
pub static ref PROJECT_DIRS: BatProjectDirs =
BatProjectDirs::new().expect("Could not get home directory");
}
pub static PROJECT_DIRS: Lazy<BatProjectDirs> =
Lazy::new(|| BatProjectDirs::new().expect("Could not get home directory"));