File tree Expand file tree Collapse file tree 3 files changed +6
-2
lines changed Expand file tree Collapse file tree 3 files changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -714,6 +714,8 @@ impl ops::Deref for CString {
714
714
}
715
715
}
716
716
717
+ /// Delegates to the [`CStr`] implementation of [`fmt::Debug`],
718
+ /// showing invalid UTF-8 as hex escapes.
717
719
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
718
720
impl fmt:: Debug for CString {
719
721
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
Original file line number Diff line number Diff line change @@ -162,10 +162,12 @@ impl fmt::Display for FromBytesUntilNulError {
162
162
}
163
163
}
164
164
165
+ /// Shows the underlying bytes as a normal string, with invalid UTF-8
166
+ /// presented as hex escape sequences.
165
167
#[ stable( feature = "cstr_debug" , since = "1.3.0" ) ]
166
168
impl fmt:: Debug for CStr {
167
169
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
168
- write ! ( f , " \" {} \" " , self . to_bytes( ) . escape_ascii ( ) )
170
+ fmt :: Debug :: fmt ( crate :: bstr :: ByteStr :: from_bytes ( self . to_bytes ( ) ) , f )
169
171
}
170
172
}
171
173
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ fn compares_as_u8s() {
17
17
#[ test]
18
18
fn debug ( ) {
19
19
let s = c"abc\x01 \x02 \n \xE2 \x80 \xA6 \xFF " ;
20
- assert_eq ! ( format!( "{s:?}" ) , r#" "abc\x01\x02\n\xe2\x80\xa6\ xff""# ) ;
20
+ assert_eq ! ( format!( "{s:?}" ) , " \ " abc\\ x01\\ x02\\ n… \\ xff\" " ) ;
21
21
}
22
22
23
23
#[ test]
You can’t perform that action at this time.
0 commit comments