Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
impl Default for Values + OsValues for any lifetime.
  • Loading branch information
kennytm authored and kbknapp committed Jul 21, 2017
1 parent 4030c55 commit fb7d623
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/args/arg_matches.rs
Expand Up @@ -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:
Expand All @@ -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`].
Expand Down Expand Up @@ -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:
Expand All @@ -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);
}

0 comments on commit fb7d623

Please sign in to comment.