While trying to open a non-existing file (on Windows 10, Chinese):
use std::fs::File;
fn main() {
File::open("no-such-file.rs").unwrap();
}
It panicked with a message:
thread '<main>' panicked at 'called `Result::unwrap()` on an `Err` value: Error { repr: Os { code: 2, message: "\u{7cfb}\u{7edf}\u{627e}\u{4e0d}\u{5230}\u{6307}\u{5b9a}\u{7684}\u{6587}\u{4ef6}\u{3002}" } }', ../src/libcore\result.rs:746
note: Run with `RUST_BACKTRACE=1` for a backtrace.
The OS native error message here is unreadable for human being.
The message ("\u{7cfb}\u{7edf}\u{627e}\u{4e0d}\u{5230}...") is the escaped result of "No such file or directory" in Chinese ("系统找不到指定的文件")。impl fmt::Debug for str do this escape.
I can read Chinese, which is my mother tongue, but I can't read \u{7cfb}....
Possible solutions:
- Don't use local language (Chinese here) OS error string, use English instead.
- Change
impl fmt::Debug for str to not escape most Unicode chars. (breaking-change?)
fn main() {
let s = "Hello δεΣ❤ 日月";
println!("{}", s); // prints "Hello δεΣ❤ 日月"
println!("{:?}", s); // prints "Hello \u{3b4}\u{3b5}\u{3a3}\u{2764} \u{65e5}\u{6708}"
}
Run it on play.rust-lang.org
Is impl fmt::Debug for str really friendly enough for debug purpose? Is there possibility that we change its implementation as similar as impl fmt::Display for str?
While trying to open a non-existing file (on Windows 10, Chinese):
It panicked with a message:
The OS native error message here is unreadable for human being.
The message (
"\u{7cfb}\u{7edf}\u{627e}\u{4e0d}\u{5230}...") is the escaped result of "No such file or directory" in Chinese ("系统找不到指定的文件")。impl fmt::Debug for strdo this escape.I can read Chinese, which is my mother tongue, but I can't read
\u{7cfb}....Possible solutions:
impl fmt::Debug for strto not escape most Unicode chars. (breaking-change?)Run it on play.rust-lang.org
Is
impl fmt::Debug for strreally friendly enough for debug purpose? Is there possibility that we change its implementation as similar asimpl fmt::Display for str?