Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write Cyrillic text when using the debugging format?

Tags:

rust

cyrillic

While using println! works as expected:

println!("Привет!"); // Привет!

With debugging format however:

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 any way to have assert! print correctly in debug format?

like image 829
latrasis Avatar asked Feb 08 '16 07:02

latrasis


1 Answers

So far as Rust is concerned, it is correct. The implementation of Debug for str restricts itself to printable ASCII characters so that the output is readable irrespective of codepage or output mechanism.

I don't believe there's anything you can do to change this for strings in general; on a case-by-case basis, you can use Display instead, or create a wrapper around &str that forwards to Display instead of Debug.

like image 169
DK. Avatar answered Nov 15 '22 09:11

DK.