File tree 4 files changed +59
-2
lines changed
4 files changed +59
-2
lines changed Original file line number Diff line number Diff line change @@ -712,7 +712,9 @@ impl DoubleEndedIterator for Args {
712
712
#[ stable( feature = "std_debug" , since = "1.16.0" ) ]
713
713
impl fmt:: Debug for Args {
714
714
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
715
- f. pad ( "Args { .. }" )
715
+ f. debug_struct ( "Args" )
716
+ . field ( "inner" , & self . inner . inner . inner_debug ( ) )
717
+ . finish ( )
716
718
}
717
719
}
718
720
@@ -737,7 +739,9 @@ impl DoubleEndedIterator for ArgsOs {
737
739
#[ stable( feature = "std_debug" , since = "1.16.0" ) ]
738
740
impl fmt:: Debug for ArgsOs {
739
741
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
740
- f. pad ( "ArgsOs { .. }" )
742
+ f. debug_struct ( "ArgsOs" )
743
+ . field ( "inner" , & self . inner . inner_debug ( ) )
744
+ . finish ( )
741
745
}
742
746
}
743
747
@@ -1085,4 +1089,14 @@ mod tests {
1085
1089
r#""c:\te;st";c:\"# ) ) ;
1086
1090
assert ! ( join_paths( [ r#"c:\te"st"# ] . iter( ) . cloned( ) ) . is_err( ) ) ;
1087
1091
}
1092
+
1093
+ #[ test]
1094
+ fn args_debug ( ) {
1095
+ assert_eq ! (
1096
+ format!( "Args {{ inner: {:?} }}" , args( ) . collect:: <Vec <_>>( ) ) ,
1097
+ format!( "{:?}" , args( ) ) ) ;
1098
+ assert_eq ! (
1099
+ format!( "ArgsOs {{ inner: {:?} }}" , args_os( ) . collect:: <Vec <_>>( ) ) ,
1100
+ format!( "{:?}" , args_os( ) ) ) ;
1088
1101
}
1102
+ }
Original file line number Diff line number Diff line change @@ -35,6 +35,12 @@ pub struct Args {
35
35
_dont_send_or_sync_me : PhantomData < * mut ( ) > ,
36
36
}
37
37
38
+ impl Args {
39
+ pub fn inner_debug ( & self ) -> & [ OsString ] {
40
+ self . iter . as_slice ( )
41
+ }
42
+ }
43
+
38
44
impl Iterator for Args {
39
45
type Item = OsString ;
40
46
fn next ( & mut self ) -> Option < OsString > { self . iter . next ( ) }
Original file line number Diff line number Diff line change @@ -35,6 +35,12 @@ pub struct Args {
35
35
_dont_send_or_sync_me : PhantomData < * mut ( ) > ,
36
36
}
37
37
38
+ impl Args {
39
+ pub fn inner_debug ( & self ) -> & [ OsString ] {
40
+ self . iter . as_slice ( )
41
+ }
42
+ }
43
+
38
44
impl Iterator for Args {
39
45
type Item = OsString ;
40
46
fn next ( & mut self ) -> Option < OsString > { self . iter . next ( ) }
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ use slice;
16
16
use ops:: Range ;
17
17
use ffi:: OsString ;
18
18
use libc:: { c_int, c_void} ;
19
+ use fmt;
19
20
20
21
pub unsafe fn init ( _argc : isize , _argv : * const * const u8 ) { }
21
22
@@ -39,6 +40,36 @@ pub struct Args {
39
40
cur : * mut * mut u16 ,
40
41
}
41
42
43
+ pub struct ArgsInnerDebug < ' a > {
44
+ args : & ' a Args ,
45
+ }
46
+
47
+ impl < ' a > fmt:: Debug for ArgsInnerDebug < ' a > {
48
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
49
+ f. write_str ( "[" ) ?;
50
+ let mut first = true ;
51
+ for i in self . args . range . clone ( ) {
52
+ if !first {
53
+ f. write_str ( ", " ) ?;
54
+ }
55
+ first = false ;
56
+
57
+ // Here we do allocation which could be avoided.
58
+ fmt:: Debug :: fmt ( & unsafe { os_string_from_ptr ( * self . args . cur . offset ( i) ) } , f) ?;
59
+ }
60
+ f. write_str ( "]" ) ?;
61
+ Ok ( ( ) )
62
+ }
63
+ }
64
+
65
+ impl Args {
66
+ pub fn inner_debug ( & self ) -> ArgsInnerDebug {
67
+ ArgsInnerDebug {
68
+ args : self
69
+ }
70
+ }
71
+ }
72
+
42
73
unsafe fn os_string_from_ptr ( ptr : * mut u16 ) -> OsString {
43
74
let mut len = 0 ;
44
75
while * ptr. offset ( len) != 0 { len += 1 ; }
You can’t perform that action at this time.
0 commit comments