How to write cyrillic text using debug format?

When using println! works as expected:

 println!("!"); // ! 

With debug format:

 println!("{:?}", "!"); // "\u{41f}\u{440}\u{438}\u{432}\u{435}\u{442}!" 

Using assert! :

 assert!("!" != "!") // 'assertion failed: "\u{41f}\u{440}\u{438}\u{432}\u{435}\u{442}!" != "\u{41f}\u{440}\u{438}\u{432}\u{435}\u{442}!" 

Is there a way to print assert! correctly assert! in debug format?

+5
source share
1 answer

As for rust, that's right. The Debug implementation for str limits itself to printable ASCII characters, so the output is readable regardless of the code page or output mechanism.

I do not believe that you can do this to change this for strings in general; on an individual basis, you can use Display instead, or create a wrapper around &str that forwards Display instead of Debug .

+7
source

Source: https://habr.com/ru/post/1242514/


All Articles