impl Default for Values + OsValues for any lifetime.

This commit is contained in:
kennytm 2017-07-09 22:04:17 +08:00 committed by Kevin K
parent 4030c5529d
commit fb7d6231f1

View file

@ -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);
}