Trait print_bytes::ToBytes
source · [−]Expand description
Represents a type similarly to Display
.
Implement this trait to allow printing a type that cannot guarantee UTF-8 output. It is used to bound values accepted by functions in this crate.
Examples
use print_bytes::println_lossy;
use print_bytes::ByteStr;
use print_bytes::ToBytes;
#[cfg(windows)]
use print_bytes::WideStr;
struct ByteSlice<'a>(&'a [u8]);
impl ToBytes for ByteSlice<'_> {
fn to_bytes(&self) -> ByteStr<'_> {
self.0.to_bytes()
}
#[cfg(windows)]
fn to_wide(&self) -> Option<WideStr> {
self.0.to_wide()
}
}
println_lossy(&ByteSlice(b"Hello, world!"));