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?
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With