@@ -837,6 +837,25 @@ impl<'a> AsRef<OsStr> for Components<'a> {
837
837
}
838
838
}
839
839
840
+ #[ stable( feature = "path_iter_debug" , since = "1.13.0" ) ]
841
+ impl < ' a > fmt:: Debug for Iter < ' a > {
842
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
843
+ struct DebugHelper < ' a > ( & ' a Path ) ;
844
+
845
+ impl < ' a > fmt:: Debug for DebugHelper < ' a > {
846
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
847
+ f. debug_list ( )
848
+ . entries ( self . 0 . iter ( ) )
849
+ . finish ( )
850
+ }
851
+ }
852
+
853
+ f. debug_tuple ( "Iter" )
854
+ . field ( & DebugHelper ( self . as_path ( ) ) )
855
+ . finish ( )
856
+ }
857
+ }
858
+
840
859
impl < ' a > Iter < ' a > {
841
860
/// Extracts a slice corresponding to the portion of the path remaining for iteration.
842
861
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -3523,4 +3542,26 @@ mod tests {
3523
3542
let actual = format ! ( "{:?}" , components) ;
3524
3543
assert_eq ! ( expected, actual) ;
3525
3544
}
3545
+
3546
+ #[ cfg( unix) ]
3547
+ #[ test]
3548
+ fn test_iter_debug ( ) {
3549
+ let path = Path :: new ( "/tmp" ) ;
3550
+
3551
+ let mut iter = path. iter ( ) ;
3552
+
3553
+ let expected = "Iter([\" /\" , \" tmp\" ])" ;
3554
+ let actual = format ! ( "{:?}" , iter) ;
3555
+ assert_eq ! ( expected, actual) ;
3556
+
3557
+ let _ = iter. next ( ) . unwrap ( ) ;
3558
+ let expected = "Iter([\" tmp\" ])" ;
3559
+ let actual = format ! ( "{:?}" , iter) ;
3560
+ assert_eq ! ( expected, actual) ;
3561
+
3562
+ let _ = iter. next ( ) . unwrap ( ) ;
3563
+ let expected = "Iter([])" ;
3564
+ let actual = format ! ( "{:?}" , iter) ;
3565
+ assert_eq ! ( expected, actual) ;
3566
+ }
3526
3567
}
0 commit comments