Use fmt::Debug implementation for Lua string from bstr

This commit is contained in:
Alex Orlenko
2024-09-26 22:46:02 +01:00
parent fb0c0d9ee9
commit 4dddf3c18d
2 changed files with 3 additions and 18 deletions
+2 -17
View File
@@ -143,23 +143,8 @@ impl fmt::Debug for String {
}
// Format as bytes
write!(f, "b\"")?;
for &b in bytes {
// https://doc.rust-lang.org/reference/tokens.html#byte-escapes
match b {
b'\n' => write!(f, "\\n")?,
b'\r' => write!(f, "\\r")?,
b'\t' => write!(f, "\\t")?,
b'\\' | b'"' => write!(f, "\\{}", b as char)?,
b'\0' => write!(f, "\\0")?,
// ASCII printable
0x20..=0x7e => write!(f, "{}", b as char)?,
_ => write!(f, "\\x{b:02x}")?,
}
}
write!(f, "\"")?;
Ok(())
write!(f, "b")?;
<bstr::BStr as fmt::Debug>::fmt(bstr::BStr::new(&bytes), f)
}
}