1+ use alloc:: string:: String ;
12use rustpython_wtf8:: { CodePoint , Wtf8 } ;
23
34#[ derive( Debug , PartialEq , Eq , Copy , Clone , Hash , is_macro:: Is ) ]
@@ -55,9 +56,9 @@ pub unsafe trait Escape {
5556 /// # Safety
5657 ///
5758 /// This string must only contain printable characters.
58- unsafe fn write_source ( & self , formatter : & mut impl std :: fmt:: Write ) -> core:: fmt:: Result ;
59- fn write_body_slow ( & self , formatter : & mut impl std :: fmt:: Write ) -> core:: fmt:: Result ;
60- fn write_body ( & self , formatter : & mut impl std :: fmt:: Write ) -> core:: fmt:: Result {
59+ unsafe fn write_source ( & self , formatter : & mut impl core :: fmt:: Write ) -> core:: fmt:: Result ;
60+ fn write_body_slow ( & self , formatter : & mut impl core :: fmt:: Write ) -> core:: fmt:: Result ;
61+ fn write_body ( & self , formatter : & mut impl core :: fmt:: Write ) -> core:: fmt:: Result {
6162 if self . changed ( ) {
6263 self . write_body_slow ( formatter)
6364 } else {
@@ -117,7 +118,7 @@ impl<'a> UnicodeEscape<'a> {
117118pub struct StrRepr < ' r , ' a > ( & ' r UnicodeEscape < ' a > ) ;
118119
119120impl StrRepr < ' _ , ' _ > {
120- pub fn write ( & self , formatter : & mut impl std :: fmt:: Write ) -> core:: fmt:: Result {
121+ pub fn write ( & self , formatter : & mut impl core :: fmt:: Write ) -> core:: fmt:: Result {
121122 let quote = self . 0 . layout ( ) . quote . to_char ( ) ;
122123 formatter. write_char ( quote) ?;
123124 self . 0 . write_body ( formatter) ?;
@@ -216,7 +217,7 @@ impl UnicodeEscape<'_> {
216217 fn write_char (
217218 ch : CodePoint ,
218219 quote : Quote ,
219- formatter : & mut impl std :: fmt:: Write ,
220+ formatter : & mut impl core :: fmt:: Write ,
220221 ) -> core:: fmt:: Result {
221222 let Some ( ch) = ch. to_char ( ) else {
222223 return write ! ( formatter, "\\ u{:04x}" , ch. to_u32( ) ) ;
@@ -260,15 +261,15 @@ unsafe impl Escape for UnicodeEscape<'_> {
260261 & self . layout
261262 }
262263
263- unsafe fn write_source ( & self , formatter : & mut impl std :: fmt:: Write ) -> core:: fmt:: Result {
264+ unsafe fn write_source ( & self , formatter : & mut impl core :: fmt:: Write ) -> core:: fmt:: Result {
264265 formatter. write_str ( unsafe {
265266 // SAFETY: this function must be called only when source is printable characters (i.e. no surrogates)
266- std :: str:: from_utf8_unchecked ( self . source . as_bytes ( ) )
267+ core :: str:: from_utf8_unchecked ( self . source . as_bytes ( ) )
267268 } )
268269 }
269270
270271 #[ cold]
271- fn write_body_slow ( & self , formatter : & mut impl std :: fmt:: Write ) -> core:: fmt:: Result {
272+ fn write_body_slow ( & self , formatter : & mut impl core :: fmt:: Write ) -> core:: fmt:: Result {
272273 for ch in self . source . code_points ( ) {
273274 Self :: write_char ( ch, self . layout ( ) . quote , formatter) ?;
274275 }
@@ -378,7 +379,11 @@ impl AsciiEscape<'_> {
378379 }
379380 }
380381
381- fn write_char ( ch : u8 , quote : Quote , formatter : & mut impl std:: fmt:: Write ) -> core:: fmt:: Result {
382+ fn write_char (
383+ ch : u8 ,
384+ quote : Quote ,
385+ formatter : & mut impl core:: fmt:: Write ,
386+ ) -> core:: fmt:: Result {
382387 match ch {
383388 b'\t' => formatter. write_str ( "\\ t" ) ,
384389 b'\n' => formatter. write_str ( "\\ n" ) ,
@@ -404,15 +409,15 @@ unsafe impl Escape for AsciiEscape<'_> {
404409 & self . layout
405410 }
406411
407- unsafe fn write_source ( & self , formatter : & mut impl std :: fmt:: Write ) -> core:: fmt:: Result {
412+ unsafe fn write_source ( & self , formatter : & mut impl core :: fmt:: Write ) -> core:: fmt:: Result {
408413 formatter. write_str ( unsafe {
409414 // SAFETY: this function must be called only when source is printable ascii characters
410- std :: str:: from_utf8_unchecked ( self . source )
415+ core :: str:: from_utf8_unchecked ( self . source )
411416 } )
412417 }
413418
414419 #[ cold]
415- fn write_body_slow ( & self , formatter : & mut impl std :: fmt:: Write ) -> core:: fmt:: Result {
420+ fn write_body_slow ( & self , formatter : & mut impl core :: fmt:: Write ) -> core:: fmt:: Result {
416421 for ch in self . source {
417422 Self :: write_char ( * ch, self . layout ( ) . quote , formatter) ?;
418423 }
@@ -423,7 +428,7 @@ unsafe impl Escape for AsciiEscape<'_> {
423428pub struct BytesRepr < ' r , ' a > ( & ' r AsciiEscape < ' a > ) ;
424429
425430impl BytesRepr < ' _ , ' _ > {
426- pub fn write ( & self , formatter : & mut impl std :: fmt:: Write ) -> core:: fmt:: Result {
431+ pub fn write ( & self , formatter : & mut impl core :: fmt:: Write ) -> core:: fmt:: Result {
427432 let quote = self . 0 . layout ( ) . quote . to_char ( ) ;
428433 formatter. write_char ( 'b' ) ?;
429434 formatter. write_char ( quote) ?;
0 commit comments