File tree Expand file tree Collapse file tree
library/std/src/sys_common Expand file tree Collapse file tree Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 2121mod tests;
2222
2323pub mod backtrace;
24- pub mod bytestring;
2524pub mod condvar;
2625pub mod fs;
2726pub mod io;
Original file line number Diff line number Diff line change 22//! systems: just a `Vec<u8>`/`[u8]`.
33
44use crate :: borrow:: Cow ;
5-
65use crate :: fmt;
6+ use crate :: fmt:: Write ;
77use crate :: mem;
88use crate :: rc:: Rc ;
99use crate :: str;
1010use crate :: sync:: Arc ;
11- use crate :: sys_common:: bytestring:: debug_fmt_bytestring;
1211use crate :: sys_common:: { AsInner , IntoInner } ;
1312
14- use core:: str:: lossy:: Utf8Lossy ;
13+ use core:: str:: lossy:: { Utf8Lossy , Utf8LossyChunk } ;
14+
15+ #[ cfg( test) ]
16+ mod tests;
1517
1618#[ derive( Hash ) ]
1719#[ repr( transparent) ]
@@ -26,7 +28,19 @@ pub struct Slice {
2628
2729impl fmt:: Debug for Slice {
2830 fn fmt ( & self , formatter : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
29- debug_fmt_bytestring ( & self . inner , formatter)
31+ // Writes out a valid unicode string with the correct escape sequences
32+
33+ formatter. write_str ( "\" " ) ?;
34+ for Utf8LossyChunk { valid, broken } in Utf8Lossy :: from_bytes ( & self . inner ) . chunks ( ) {
35+ for c in valid. chars ( ) . flat_map ( |c| c. escape_debug ( ) ) {
36+ formatter. write_char ( c) ?
37+ }
38+
39+ for b in broken {
40+ write ! ( formatter, "\\ x{:02X}" , b) ?;
41+ }
42+ }
43+ formatter. write_str ( "\" " )
3044 }
3145}
3246
Original file line number Diff line number Diff line change 1+ use super :: * ;
2+
3+ #[ test]
4+ fn slice_debug_output ( ) {
5+ let input = Slice :: from_u8_slice ( b"\xF0 hello,\t world" ) ;
6+ let expected = r#""\xF0hello,\tworld""# ;
7+ let output = format ! ( "{:?}" , input) ;
8+
9+ assert_eq ! ( output, expected) ;
10+ }
You can’t perform that action at this time.
0 commit comments