@@ -87,14 +87,22 @@ where
87
87
88
88
impl fmt:: Debug for Interned < str > {
89
89
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
90
- write ! ( f, "{:?}" , self . 0 )
90
+ if f. alternate ( ) {
91
+ write ! ( f, "{:#?}" , self . 0 )
92
+ } else {
93
+ write ! ( f, "{:?}" , self . 0 )
94
+ }
91
95
}
92
96
}
93
97
94
98
#[ cfg( feature = "bytes" ) ]
95
99
impl fmt:: Debug for Interned < [ u8 ] > {
96
100
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
97
- write ! ( f, "{:?}" , self . 0 )
101
+ if f. alternate ( ) {
102
+ write ! ( f, "{:#?}" , self . 0 )
103
+ } else {
104
+ write ! ( f, "{:?}" , self . 0 )
105
+ }
98
106
}
99
107
}
100
108
@@ -307,20 +315,24 @@ where
307
315
}
308
316
309
317
impl fmt:: Debug for Slice < str > {
318
+ /// Formats the string slice using the given formatter.
310
319
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
311
- match self {
312
- Self :: Static ( _) => write ! ( f, "Static({:?})" , self ) ,
313
- Self :: Owned ( _) => write ! ( f, "Owned({:?})" , self ) ,
314
- }
320
+ write ! ( f, "{:?}" , self . as_slice( ) )
315
321
}
316
322
}
317
323
318
324
#[ cfg( feature = "bytes" ) ]
319
325
impl fmt:: Debug for Slice < [ u8 ] > {
326
+ /// Formats the byte slice using the given formatter.
327
+ ///
328
+ /// If alternate format is specified, e.g. `{:#?}`, the slice is assumed to
329
+ /// be conventionally UTF-8 and converted to a [`String`] lossily with
330
+ /// [`String::from_utf8_lossy`].
320
331
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
321
- match self {
322
- Self :: Static ( _) => write ! ( f, "Static({:?})" , String :: from_utf8_lossy( self . as_slice( ) ) ) ,
323
- Self :: Owned ( _) => write ! ( f, "Owned({:?})" , String :: from_utf8_lossy( self . as_slice( ) ) ) ,
332
+ if f. alternate ( ) {
333
+ write ! ( f, "{:?}" , String :: from_utf8_lossy( self . as_slice( ) ) )
334
+ } else {
335
+ write ! ( f, "{:?}" , self . as_slice( ) )
324
336
}
325
337
}
326
338
}
0 commit comments