Skip to content

Commit

Permalink
Merge pull request #4081 from epage/into_iter
Browse files Browse the repository at this point in the history
fix!: Prefer `IntoIterator` over `&[]`
  • Loading branch information
epage committed Aug 15, 2022
2 parents dcfbee9 + 2de5919 commit 472ede9
Show file tree
Hide file tree
Showing 17 changed files with 165 additions and 139 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -42,6 +42,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
`Command::disable_version_flag`) and mark the custom flags as `global(true)`.
- Looking up a group in `ArgMatches` now returns the arg `Id`s, rather than the values.
- Various `Arg`, `Command`, and `ArgGroup` calls were switched from accepting `&[]` to `[]` via `IntoIterator`
- `Arg::short_aliases` and other builder functions that took `&[]` need the `&` dropped
- *(help)* Make `DeriveDisplayOrder` the default and removed the setting. To sort help, set `next_display_order(None)` (#2808)
- *(help)* Subcommand display order respects `Command::next_display_order` instead of `DeriveDisplayOrder` and using its own initial display order value (#2808)
- *(env)* Parse `--help` and `--version` like any `ArgAction::SetTrue` flag (#3776)
Expand Down
10 changes: 5 additions & 5 deletions clap_bench/benches/03_complex.rs
Expand Up @@ -13,7 +13,7 @@ macro_rules! create_app {
.arg(arg!(-o --option <opt> ... "tests options").required(false))
.arg(arg!([positional] "tests positionals"))
.arg(arg!(-f --flag ... "tests flags").global(true))
.args(&[
.args([
arg!(flag2: -F "tests flags with exclusions")
.conflicts_with("flag")
.requires("option2"),
Expand All @@ -27,10 +27,10 @@ macro_rules! create_app {
.value_parser(OPT3_VALS),
arg!([positional3] ... "tests positionals with specific values")
.value_parser(POS3_VALS),
arg!(--multvals <s> "Tests multiple values not mult occs").required(false).value_names(&["one", "two"]),
arg!(--multvals <s> "Tests multiple values not mult occs").required(false).value_names(["one", "two"]),
arg!(
--multvalsmo <s> "Tests multiple values, not mult occs"
).required(false).value_names(&["one", "two"]),
).required(false).value_names(["one", "two"]),
arg!(--minvals2 <minvals> ... "Tests 2 min vals").num_args(2..).required(false),
arg!(--maxvals3 <maxvals> ... "Tests 3 max vals").num_args(1..=3).required(false),
])
Expand Down Expand Up @@ -109,14 +109,14 @@ pub fn build_from_builder(c: &mut Criterion) {
Arg::new("multvals")
.long("multvals")
.help("Tests multiple values, not mult occs")
.value_names(&["one", "two"]),
.value_names(["one", "two"]),
)
.arg(
Arg::new("multvalsmo")
.long("multvalsmo")
.action(ArgAction::Append)
.help("Tests multiple values, not mult occs")
.value_names(&["one", "two"]),
.value_names(["one", "two"]),
)
.arg(
Arg::new("minvals")
Expand Down
2 changes: 1 addition & 1 deletion clap_bench/benches/04_new_help.rs
Expand Up @@ -45,7 +45,7 @@ fn app_example3<'c>() -> Command<'c> {
.short('d')
.action(ArgAction::SetTrue),
)
.args(&[
.args([
Arg::new("config")
.help("sets the config file to use")
.action(ArgAction::Set)
Expand Down
8 changes: 4 additions & 4 deletions clap_derive/src/attrs.rs
Expand Up @@ -561,7 +561,7 @@ impl Attrs {
static DEFAULT_VALUES: clap::__macro_refs::once_cell::sync::Lazy<Vec<&str>> = clap::__macro_refs::once_cell::sync::Lazy::new(|| {
iter_to_vals(#expr)
});
&*DEFAULT_VALUES.as_slice()
DEFAULT_VALUES.iter().copied()
}
})
} else {
Expand All @@ -582,7 +582,7 @@ impl Attrs {
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.as_slice()
DEFAULT_VALUES.iter().copied()
}
})
};
Expand Down Expand Up @@ -677,7 +677,7 @@ impl Attrs {
static DEFAULT_VALUES: clap::__macro_refs::once_cell::sync::Lazy<Vec<&::std::ffi::OsStr>> = clap::__macro_refs::once_cell::sync::Lazy::new(|| {
iter_to_vals(#expr)
});
&*DEFAULT_VALUES.as_slice()
DEFAULT_VALUES.iter().copied()
}
})
} else {
Expand All @@ -698,7 +698,7 @@ impl Attrs {
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.as_slice()
DEFAULT_VALUES.iter().copied()
}
})
};
Expand Down

0 comments on commit 472ede9

Please sign in to comment.