@@ -837,6 +837,25 @@ impl<'a> AsRef<OsStr> for Components<'a> {
837837 }
838838}
839839
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+
840859impl < ' a > Iter < ' a > {
841860 /// Extracts a slice corresponding to the portion of the path remaining for iteration.
842861 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -3523,4 +3542,26 @@ mod tests {
35233542 let actual = format ! ( "{:?}" , components) ;
35243543 assert_eq ! ( expected, actual) ;
35253544 }
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+ }
35263567}
0 commit comments