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 {
714714    } 
715715} 
716716
717+ /// Delegates to the [`CStr`] implementation of [`fmt::Debug`], 
718+ /// showing invalid UTF-8 as hex escapes. 
717719#[ stable( feature = "rust1" ,  since = "1.0.0" ) ]  
718720impl  fmt:: Debug  for  CString  { 
719721    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 {
162162    } 
163163} 
164164
165+ /// Shows the underlying bytes as a normal string, with invalid UTF-8 
166+ /// presented as hex escape sequences. 
165167#[ stable( feature = "cstr_debug" ,  since = "1.3.0" ) ]  
166168impl  fmt:: Debug  for  CStr  { 
167169    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 ) 
169171    } 
170172} 
171173
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ fn compares_as_u8s() {
1717#[ test]  
1818fn  debug ( )  { 
1919    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:?}" ) ,  r#""abc\x01\x02\n… \xff""# ) ; 
2121} 
2222
2323#[ test]  
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments