How to write Cyrillic text when using the debugging format?
Asked Answered
B

1

5

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?

Barrelhouse answered 8/2, 2016 at 7:55 Comment(0)
A
7

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.

Amyotonia answered 8/2, 2016 at 8:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.