File tree 5 files changed +28
-50
lines changed
library/std/src/sys_common
5 files changed +28
-50
lines changed Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 21
21
mod tests;
22
22
23
23
pub mod backtrace;
24
- pub mod bytestring;
25
24
pub mod condvar;
26
25
pub mod fs;
27
26
pub mod io;
Original file line number Diff line number Diff line change 2
2
//! systems: just a `Vec<u8>`/`[u8]`.
3
3
4
4
use crate :: borrow:: Cow ;
5
-
6
5
use crate :: fmt;
6
+ use crate :: fmt:: Write ;
7
7
use crate :: mem;
8
8
use crate :: rc:: Rc ;
9
9
use crate :: str;
10
10
use crate :: sync:: Arc ;
11
- use crate :: sys_common:: bytestring:: debug_fmt_bytestring;
12
11
use crate :: sys_common:: { AsInner , IntoInner } ;
13
12
14
- use core:: str:: lossy:: Utf8Lossy ;
13
+ use core:: str:: lossy:: { Utf8Lossy , Utf8LossyChunk } ;
14
+
15
+ #[ cfg( test) ]
16
+ mod tests;
15
17
16
18
#[ derive( Hash ) ]
17
19
#[ repr( transparent) ]
@@ -26,7 +28,19 @@ pub struct Slice {
26
28
27
29
impl fmt:: Debug for Slice {
28
30
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 ( "\" " )
30
44
}
31
45
}
32
46
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