printbuf_to_formatter: Lossy display of non-UTF-8 printbufs

Use to_string_lossy in printbuf_to_formatter, which tolerates
non-UTF-8 strings (by using replacement characters).

This is used in various Display impls, and allows something like:
bcachefs list --btree dirents
with non-UTF-8 paths.
This commit is contained in:
Gabriel 2024-01-29 14:33:15 +01:00
parent da4bbf51d0
commit f8f10530f1

View File

@ -164,5 +164,5 @@ pub fn printbuf_to_formatter<F>(f: &mut fmt::Formatter<'_>, func: F) -> fmt::Res
func(&mut buf);
let s = unsafe { CStr::from_ptr(buf.buf) };
f.write_str(s.to_str().unwrap())
f.write_str(&s.to_string_lossy())
}