@@ -567,6 +567,22 @@ impl<'a> DoubleEndedIterator for Values<'a> {
567
567
568
568
impl < ' a > ExactSizeIterator for Values < ' a > { }
569
569
570
+ /// Creates an empty iterator.
571
+ impl Default for Values < ' static > {
572
+ fn default ( ) -> Self {
573
+ static EMPTY : [ OsString ; 0 ] = [ ] ;
574
+ // This is never called because the iterator is empty:
575
+ fn to_str_slice ( _: & OsString ) -> & str { unreachable ! ( ) } ;
576
+ Values { iter : EMPTY [ ..] . iter ( ) . map ( to_str_slice) }
577
+ }
578
+ }
579
+
580
+ #[ test]
581
+ fn test_default_values ( ) {
582
+ let mut values: Values = Values :: default ( ) ;
583
+ assert_eq ! ( values. next( ) , None ) ;
584
+ }
585
+
570
586
/// An iterator for getting multiple values out of an argument via the [`ArgMatches::values_of_os`]
571
587
/// method. Usage of this iterator allows values which contain invalid UTF-8 code points unlike
572
588
/// [`Values`].
@@ -604,3 +620,19 @@ impl<'a> Iterator for OsValues<'a> {
604
620
impl < ' a > DoubleEndedIterator for OsValues < ' a > {
605
621
fn next_back ( & mut self ) -> Option < & ' a OsStr > { self . iter . next_back ( ) }
606
622
}
623
+
624
+ /// Creates an empty iterator.
625
+ impl Default for OsValues < ' static > {
626
+ fn default ( ) -> Self {
627
+ static EMPTY : [ OsString ; 0 ] = [ ] ;
628
+ // This is never called because the iterator is empty:
629
+ fn to_str_slice ( _: & OsString ) -> & OsStr { unreachable ! ( ) } ;
630
+ OsValues { iter : EMPTY [ ..] . iter ( ) . map ( to_str_slice) }
631
+ }
632
+ }
633
+
634
+ #[ test]
635
+ fn test_default_osvalues ( ) {
636
+ let mut values: OsValues = OsValues :: default ( ) ;
637
+ assert_eq ! ( values. next( ) , None ) ;
638
+ }
0 commit comments