File tree Expand file tree Collapse file tree 4 files changed +59
-2
lines changed Expand file tree Collapse file tree 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 {
741741#[ stable( feature = "std_debug" , since = "1.16.0" ) ]
742742impl fmt:: Debug for Args {
743743 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 ( )
745747 }
746748}
747749
@@ -766,7 +768,9 @@ impl DoubleEndedIterator for ArgsOs {
766768#[ stable( feature = "std_debug" , since = "1.16.0" ) ]
767769impl fmt:: Debug for ArgsOs {
768770 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 ( )
770774 }
771775}
772776
@@ -1114,4 +1118,14 @@ mod tests {
11141118 r#""c:\te;st";c:\"# ) ) ;
11151119 assert ! ( join_paths( [ r#"c:\te"st"# ] . iter( ) . cloned( ) ) . is_err( ) ) ;
11161120 }
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( ) ) ) ;
11171130 }
1131+ }
Original file line number Diff line number Diff line change @@ -35,6 +35,12 @@ pub struct Args {
3535 _dont_send_or_sync_me : PhantomData < * mut ( ) > ,
3636}
3737
38+ impl Args {
39+ pub fn inner_debug ( & self ) -> & [ OsString ] {
40+ self . iter . as_slice ( )
41+ }
42+ }
43+
3844impl Iterator for Args {
3945 type Item = OsString ;
4046 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 {
3535 _dont_send_or_sync_me : PhantomData < * mut ( ) > ,
3636}
3737
38+ impl Args {
39+ pub fn inner_debug ( & self ) -> & [ OsString ] {
40+ self . iter . as_slice ( )
41+ }
42+ }
43+
3844impl Iterator for Args {
3945 type Item = OsString ;
4046 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;
1616use ops:: Range ;
1717use ffi:: OsString ;
1818use libc:: { c_int, c_void} ;
19+ use fmt;
1920
2021pub unsafe fn init ( _argc : isize , _argv : * const * const u8 ) { }
2122
@@ -39,6 +40,36 @@ pub struct Args {
3940 cur : * mut * mut u16 ,
4041}
4142
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+
4273unsafe fn os_string_from_ptr ( ptr : * mut u16 ) -> OsString {
4374 let mut len = 0 ;
4475 while * ptr. offset ( len) != 0 { len += 1 ; }
You can’t perform that action at this time.
0 commit comments