mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 14:52:33 +00:00
impl Default for Values + OsValues for any lifetime.
This commit is contained in:
parent
4030c5529d
commit
fb7d6231f1
1 changed files with 16 additions and 2 deletions
|
@ -568,7 +568,7 @@ impl<'a> DoubleEndedIterator for Values<'a> {
|
|||
impl<'a> ExactSizeIterator for Values<'a> {}
|
||||
|
||||
/// Creates an empty iterator.
|
||||
impl Default for Values<'static> {
|
||||
impl<'a> Default for Values<'a> {
|
||||
fn default() -> Self {
|
||||
static EMPTY: [OsString; 0] = [];
|
||||
// This is never called because the iterator is empty:
|
||||
|
@ -583,6 +583,13 @@ fn test_default_values() {
|
|||
assert_eq!(values.next(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_default_values_with_shorter_lifetime() {
|
||||
let matches = ArgMatches::new();
|
||||
let mut values = matches.values_of("").unwrap_or_default();
|
||||
assert_eq!(values.next(), None);
|
||||
}
|
||||
|
||||
/// An iterator for getting multiple values out of an argument via the [`ArgMatches::values_of_os`]
|
||||
/// method. Usage of this iterator allows values which contain invalid UTF-8 code points unlike
|
||||
/// [`Values`].
|
||||
|
@ -622,7 +629,7 @@ impl<'a> DoubleEndedIterator for OsValues<'a> {
|
|||
}
|
||||
|
||||
/// Creates an empty iterator.
|
||||
impl Default for OsValues<'static> {
|
||||
impl<'a> Default for OsValues<'a> {
|
||||
fn default() -> Self {
|
||||
static EMPTY: [OsString; 0] = [];
|
||||
// This is never called because the iterator is empty:
|
||||
|
@ -636,3 +643,10 @@ fn test_default_osvalues() {
|
|||
let mut values: OsValues = OsValues::default();
|
||||
assert_eq!(values.next(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_default_osvalues_with_shorter_lifetime() {
|
||||
let matches = ArgMatches::new();
|
||||
let mut values = matches.values_of_os("").unwrap_or_default();
|
||||
assert_eq!(values.next(), None);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue