Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Switch to once_cell #3829

Merged
merged 1 commit into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ color = ["atty", "termcolor"]
suggestions = ["strsim"]

# Optional
derive = ["clap_derive", "lazy_static"]
cargo = ["lazy_static"] # Disable if you're not using Cargo, enables Cargo-env-var-dependent macros
derive = ["clap_derive", "once_cell"]
cargo = ["once_cell"] # Disable if you're not using Cargo, enables Cargo-env-var-dependent macros
wrap_help = ["terminal_size", "textwrap/terminal_size"]
yaml = ["yaml-rust"]
env = [] # Use environment variables during arg parsing
Expand All @@ -101,9 +101,9 @@ yaml-rust = { version = "0.4.1", optional = true }
atty = { version = "0.2", optional = true }
termcolor = { version = "1.1.1", optional = true }
terminal_size = { version = "0.1.12", optional = true }
lazy_static = { version = "1", optional = true }
regex = { version = "1.0", optional = true }
backtrace = { version = "0.3", optional = true }
once_cell = { version = "1.12.0", optional = true }

[dev-dependencies]
regex = "1.0"
Expand Down
26 changes: 10 additions & 16 deletions clap_derive/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,14 +552,11 @@ impl Attrs {
})
} else {
quote_spanned!(ident.span()=> {
clap::lazy_static::lazy_static! {
static ref DEFAULT_VALUE: &'static str = {
let val: #ty = #val;
let s = ::std::string::ToString::to_string(&val);
::std::boxed::Box::leak(s.into_boxed_str())
};
}
*DEFAULT_VALUE
static DEFAULT_VALUE: clap::once_cell::sync::Lazy<String> = clap::once_cell::sync::Lazy::new(|| {
let val: #ty = #val;
::std::string::ToString::to_string(&val)
});
&*DEFAULT_VALUE
})
};

Expand Down Expand Up @@ -595,14 +592,11 @@ impl Attrs {
})
} else {
quote_spanned!(ident.span()=> {
clap::lazy_static::lazy_static! {
static ref DEFAULT_VALUE: &'static ::std::ffi::OsStr = {
let val: #ty = #val;
let s: ::std::ffi::OsString = val.into();
::std::boxed::Box::leak(s.into_boxed_os_str())
};
}
*DEFAULT_VALUE
static DEFAULT_VALUE: clap::once_cell::sync::Lazy<::std::ffi::OsString> = clap::once_cell::sync::Lazy::new(|| {
let val: #ty = #val;
::std::ffi::OsString = val.into()
});
&*DEFAULT_VALUE
})
};

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub use ValueEnum as ArgEnum;

#[cfg(any(feature = "derive", feature = "cargo"))]
#[doc(hidden)]
pub use lazy_static;
pub use once_cell;

#[macro_use]
#[allow(missing_docs)]
Expand Down
5 changes: 2 additions & 3 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,8 @@ macro_rules! crate_version {
#[macro_export]
macro_rules! crate_authors {
($sep:expr) => {{
clap::lazy_static::lazy_static! {
static ref CACHED: String = env!("CARGO_PKG_AUTHORS").replace(':', $sep);
}
static CACHED: clap::once_cell::sync::Lazy<String> =
clap::once_cell::sync::Lazy::new(|| env!("CARGO_PKG_AUTHORS").replace(':', $sep));

let s: &'static str = &*CACHED;
s
Expand Down