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 @@ -741,7 +741,9 @@ impl DoubleEndedIterator for Args {
741
741
#[ stable( feature = "std_debug" , since = "1.16.0" ) ]
742
742
impl fmt:: Debug for Args {
743
743
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
744
- f. pad ( "Args { .. }" )
744
+ f. debug_struct ( "Args" )
745
+ . field ( "inner" , & self . inner . inner . inner_debug ( ) )
746
+ . finish ( )
745
747
}
746
748
}
747
749
@@ -766,7 +768,9 @@ impl DoubleEndedIterator for ArgsOs {
766
768
#[ stable( feature = "std_debug" , since = "1.16.0" ) ]
767
769
impl fmt:: Debug for ArgsOs {
768
770
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
769
- f. pad ( "ArgsOs { .. }" )
771
+ f. debug_struct ( "ArgsOs" )
772
+ . field ( "inner" , & self . inner . inner_debug ( ) )
773
+ . finish ( )
770
774
}
771
775
}
772
776
@@ -1114,4 +1118,14 @@ mod tests {
1114
1118
r#""c:\te;st";c:\"# ) ) ;
1115
1119
assert ! ( join_paths( [ r#"c:\te"st"# ] . iter( ) . cloned( ) ) . is_err( ) ) ;
1116
1120
}
1121
+
1122
+ #[ test]
1123
+ fn args_debug ( ) {
1124
+ assert_eq ! (
1125
+ format!( "Args {{ inner: {:?} }}" , args( ) . collect:: <Vec <_>>( ) ) ,
1126
+ format!( "{:?}" , args( ) ) ) ;
1127
+ assert_eq ! (
1128
+ format!( "ArgsOs {{ inner: {:?} }}" , args_os( ) . collect:: <Vec <_>>( ) ) ,
1129
+ format!( "{:?}" , args_os( ) ) ) ;
1117
1130
}
1131
+ }
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