Skip to content

Commit

Permalink
Use once_cell instead of lazy_static
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Enselic committed Nov 22, 2021
1 parent dd0925a commit 5519f9c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ minimal-application = [
"atty",
"clap",
"dirs-next",
"lazy_static",
"paging",
"regex-onig",
"wild",
Expand All @@ -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 }
Expand Down
25 changes: 12 additions & 13 deletions src/bin/bat/clap_app.rs
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
8 changes: 3 additions & 5 deletions src/bin/bat/directories.rs
Original file line number Diff line number Diff line change
@@ -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`
Expand Down Expand Up @@ -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"));

0 comments on commit 5519f9c

Please sign in to comment.