Home Ask Login Register

Developers Planet

Your answer is one click away!

latrasis February 2016

How to write Cyrillic text when using the debugging format?

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?


DK. February 2016

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.

Post Status

Asked in February 2016
Viewed 1,572 times
Voted 4
Answered 1 times


Leave an answer

Quote of the day: live life