diff --git a/src/formats.rs b/src/formats.rs index d63b076..7cf12e1 100644 --- a/src/formats.rs +++ b/src/formats.rs @@ -10,8 +10,8 @@ use cfg_if::cfg_if; use snailquote::escape; use crate::findings::ScanError; -use crate::utils::{VERSION, BACKEND}; -use crate::{Findings}; +use crate::utils::{BACKEND, VERSION}; +use crate::Findings; use itertools::Itertools; /// A macro for creating an array of `Writable`s without needing to pepper your code with `into()`s. diff --git a/src/parameters.rs b/src/parameters.rs index 37c1850..929f59c 100644 --- a/src/parameters.rs +++ b/src/parameters.rs @@ -1,7 +1,7 @@ //! [Clap] struct used to parse command line arguments. use crate::string_type::String as StringType; -use crate::utils::{clap_version, clap_long_version}; +use crate::utils::{clap_long_version, clap_version}; use cfg_if::cfg_if; use clap::{AppSettings, Clap}; use std::collections::BTreeSet; diff --git a/src/utils.rs b/src/utils.rs index 8673323..946c0b9 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,5 +1,5 @@ -use once_cell::sync::OnceCell; use cfg_if::cfg_if; +use once_cell::sync::OnceCell; /// The current version of fif, as defined in Cargo.toml. pub const VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION"); @@ -23,18 +23,10 @@ static CLAP_LONG_VERSION: OnceCell = OnceCell::new(); /// Sets [`CLAP_VERSION`] to be the version defined in Cargo.toml, prefixed with a v (e.g. "v0.3.1"), then returns it as /// a String. -pub(crate) fn clap_version() -> &'static str { - CLAP_VERSION - .set(format!("v{}", VERSION.unwrap_or("???"))) - .unwrap_or_default(); // it doesn't matter if CLAP_VERSION has already been set - CLAP_VERSION.get().unwrap().as_str() -} +pub fn clap_version() -> &'static str { CLAP_VERSION.get_or_init(|| format!("v{}", VERSION.unwrap_or("???"))) } /// Sets [`CLAP_LONG_VERSION`] to be similar to [`CLAP_VERSION`], followed by the chosen backend in parentheses (e.g. /// "v0.3.1 (XDG-Mime backend)"), then returns it as a String. -pub(crate) fn clap_long_version() -> &'static str { - CLAP_LONG_VERSION - .set(format!("v{} ({} backend)", VERSION.unwrap_or("???"), BACKEND)) - .unwrap_or_default(); - CLAP_LONG_VERSION.get().unwrap().as_str() +pub fn clap_long_version() -> &'static str { + CLAP_LONG_VERSION.get_or_init(|| format!("v{} ({} backend)", VERSION.unwrap_or("???"), BACKEND)) }