@@ -639,6 +639,25 @@ pub struct Iter<'a> {
639639 inner : Components < ' a > ,
640640}
641641
642+ #[ stable( feature = "path_components_debug" , since = "1.13.0" ) ]
643+ impl < ' a > fmt:: Debug for Components < ' a > {
644+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
645+ struct DebugHelper < ' a > ( & ' a Path ) ;
646+
647+ impl < ' a > fmt:: Debug for DebugHelper < ' a > {
648+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
649+ f. debug_list ( )
650+ . entries ( self . 0 . components ( ) )
651+ . finish ( )
652+ }
653+ }
654+
655+ f. debug_tuple ( "Components" )
656+ . field ( & DebugHelper ( self . as_path ( ) ) )
657+ . finish ( )
658+ }
659+ }
660+
642661impl < ' a > Components < ' a > {
643662 // how long is the prefix, if any?
644663 #[ inline]
@@ -3483,4 +3502,25 @@ mod tests {
34833502 ) ;
34843503 }
34853504 }
3505+
3506+ #[ test]
3507+ fn test_components_debug ( ) {
3508+ let path = Path :: new ( "/tmp" ) ;
3509+
3510+ let mut components = path. components ( ) ;
3511+
3512+ let expected = "Components([RootDir, Normal(\" tmp\" )])" ;
3513+ let actual = format ! ( "{:?}" , components) ;
3514+ assert_eq ! ( expected, actual) ;
3515+
3516+ let _ = components. next ( ) . unwrap ( ) ;
3517+ let expected = "Components([Normal(\" tmp\" )])" ;
3518+ let actual = format ! ( "{:?}" , components) ;
3519+ assert_eq ! ( expected, actual) ;
3520+
3521+ let _ = components. next ( ) . unwrap ( ) ;
3522+ let expected = "Components([])" ;
3523+ let actual = format ! ( "{:?}" , components) ;
3524+ assert_eq ! ( expected, actual) ;
3525+ }
34863526}
0 commit comments