Revert "fix: Remove once_cell dependency from derive"

This reverts commit 429143af42.
This commit is contained in:
Ed Page 2022-09-16 15:49:38 -05:00
parent bbbaca2ffe
commit fe43f0c945
3 changed files with 56 additions and 22 deletions

View file

@ -69,7 +69,7 @@ suggestions = ["dep:strsim"]
# Optional
deprecated = ["clap_derive?/deprecated"] # Guided experience to prepare for next breaking release (at different stages of development, this may become default)
derive = ["clap_derive"]
derive = ["clap_derive", "dep:once_cell"]
cargo = ["dep:once_cell"] # Disable if you're not using Cargo, enables Cargo-env-var-dependent macros
wrap_help = ["dep:terminal_size"]
env = [] # Use environment variables during arg parsing

View file

@ -535,17 +535,21 @@ impl Item {
.any(|a| a.magic == Some(MagicAttrName::ValueEnum))
{
quote_spanned!(attr.name.clone().span()=> {
{
static DEFAULT_VALUE: clap::__macro_refs::once_cell::sync::Lazy<String> = clap::__macro_refs::once_cell::sync::Lazy::new(|| {
let val: #ty = #val;
clap::ValueEnum::to_possible_value(&val).unwrap().get_name().to_owned()
}
});
let s: &'static str = &*DEFAULT_VALUE;
s
})
} else {
quote_spanned!(attr.name.clone().span()=> {
{
static DEFAULT_VALUE: clap::__macro_refs::once_cell::sync::Lazy<String> = clap::__macro_refs::once_cell::sync::Lazy::new(|| {
let val: #ty = #val;
::std::string::ToString::to_string(&val)
}
});
let s: &'static str = &*DEFAULT_VALUE;
s
})
};
@ -599,21 +603,34 @@ impl Item {
})
}
iter_to_vals(#expr)
static DEFAULT_STRINGS: clap::__macro_refs::once_cell::sync::Lazy<Vec<::std::string::String>> = clap::__macro_refs::once_cell::sync::Lazy::new(|| {
iter_to_vals(#expr).collect()
});
static DEFAULT_VALUES: clap::__macro_refs::once_cell::sync::Lazy<Vec<&str>> = clap::__macro_refs::once_cell::sync::Lazy::new(|| {
DEFAULT_STRINGS.iter().map(::std::string::String::as_str).collect()
});
DEFAULT_VALUES.iter().copied()
}
})
} else {
quote_spanned!(attr.name.clone().span()=> {
{
fn iter_to_vals<T>(iterable: impl IntoIterator<Item = T>) -> Vec<String>
fn iter_to_vals<T>(iterable: impl IntoIterator<Item = T>) -> impl Iterator<Item=String>
where
T: ::std::borrow::Borrow<#inner_type>
{
iterable.into_iter().map(|val| val.borrow().to_string()).collect()
iterable.into_iter().map(|val| val.borrow().to_string())
}
iter_to_vals(#expr)
static DEFAULT_STRINGS: clap::__macro_refs::once_cell::sync::Lazy<Vec<::std::string::String>> = clap::__macro_refs::once_cell::sync::Lazy::new(|| {
iter_to_vals(#expr).collect()
});
static DEFAULT_VALUES: clap::__macro_refs::once_cell::sync::Lazy<Vec<&str>> = clap::__macro_refs::once_cell::sync::Lazy::new(|| {
DEFAULT_STRINGS.iter().map(::std::string::String::as_str).collect()
});
DEFAULT_VALUES.iter().copied()
}
})
};
@ -650,17 +667,21 @@ impl Item {
.any(|a| a.magic == Some(MagicAttrName::ValueEnum))
{
quote_spanned!(attr.name.clone().span()=> {
{
static DEFAULT_VALUE: clap::__macro_refs::once_cell::sync::Lazy<::std::ffi::OsString> = clap::__macro_refs::once_cell::sync::Lazy::new(|| {
let val: #ty = #val;
clap::ValueEnum::to_possible_value(&val).unwrap().get_name().to_owned()
}
});
let s: &'static ::std::ffi::OsStr = &*DEFAULT_VALUE;
s
})
} else {
quote_spanned!(attr.name.clone().span()=> {
{
static DEFAULT_VALUE: clap::__macro_refs::once_cell::sync::Lazy<::std::ffi::OsString> = clap::__macro_refs::once_cell::sync::Lazy::new(|| {
let val: #ty = #val;
::std::ffi::OsString::from(val)
}
});
let s: &'static ::std::ffi::OsStr = &*DEFAULT_VALUE;
s
})
};
@ -703,32 +724,45 @@ impl Item {
{
quote_spanned!(attr.name.clone().span()=> {
{
fn iter_to_vals<T>(iterable: impl IntoIterator<Item = T>) -> impl Iterator<Item=String>
fn iter_to_vals<T>(iterable: impl IntoIterator<Item = T>) -> impl Iterator<Item=::std::ffi::OsString>
where
T: ::std::borrow::Borrow<#inner_type>
{
iterable
.into_iter()
.map(|val| {
clap::ValueEnum::to_possible_value(val.borrow()).unwrap().get_name().to_owned()
clap::ValueEnum::to_possible_value(val.borrow()).unwrap().get_name().to_owned().into()
})
}
iter_to_vals(#expr)
static DEFAULT_OS_STRINGS: clap::__macro_refs::once_cell::sync::Lazy<Vec<::std::ffi::OsString>> = clap::__macro_refs::once_cell::sync::Lazy::new(|| {
iter_to_vals(#expr).collect()
});
static DEFAULT_VALUES: clap::__macro_refs::once_cell::sync::Lazy<Vec<&::std::ffi::OsStr>> = clap::__macro_refs::once_cell::sync::Lazy::new(|| {
DEFAULT_OS_STRINGS.iter().map(::std::ffi::OsString::as_os_str).collect()
});
DEFAULT_VALUES.iter().copied()
}
})
} else {
quote_spanned!(attr.name.clone().span()=> {
{
fn iter_to_vals<T>(iterable: impl IntoIterator<Item = T>) -> Vec<::std::ffi::OsString>
fn iter_to_vals<T>(iterable: impl IntoIterator<Item = T>) -> impl Iterator<Item=::std::ffi::OsString>
where
T: ::std::borrow::Borrow<#inner_type>
{
iterable.into_iter().map(|val| val.borrow().into()).collect()
iterable.into_iter().map(|val| val.borrow().into())
}
iter_to_vals(#expr)
static DEFAULT_OS_STRINGS: clap::__macro_refs::once_cell::sync::Lazy<Vec<::std::ffi::OsString>> = clap::__macro_refs::once_cell::sync::Lazy::new(|| {
iter_to_vals(#expr).collect()
});
static DEFAULT_VALUES: clap::__macro_refs::once_cell::sync::Lazy<Vec<&::std::ffi::OsStr>> = clap::__macro_refs::once_cell::sync::Lazy::new(|| {
DEFAULT_OS_STRINGS.iter().map(::std::ffi::OsString::as_os_str).collect()
});
DEFAULT_VALUES.iter().copied()
}
})
};

View file

@ -129,7 +129,7 @@ pub mod _tutorial;
#[doc(hidden)]
pub mod __macro_refs {
#[cfg(feature = "cargo")]
#[cfg(any(feature = "derive", feature = "cargo"))]
#[doc(hidden)]
pub use once_cell;
}