[−][src]Trait print_bytes::ToBytes
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.
Since Bytes
has no public constructor, implementations should call
to_bytes
on another type to create an instance.
Note: Future Compatibility
This trait should not be implemented for types that also implement
Display
or ToString
. A blanket implementation may eventually be
provided to cover those traits automatically, but that would currently be
considered a coherence violation.
Examples
use print_bytes::println_bytes; use print_bytes::Bytes; use print_bytes::ToBytes; struct ByteSlice<'a>(&'a [u8]); impl ToBytes for ByteSlice<'_> { fn to_bytes(&self) -> Bytes<'_> { self.0.to_bytes() } } println_bytes(&ByteSlice(b"Hello, world!"));
Required methods
#[must_use]fn to_bytes(&self) -> Bytes
Creates a byte sequence that will be used to represent the instance.
Implementations on Foreign Types
impl ToBytes for [u8]
[src]
impl<const N: usize> ToBytes for [u8; N]
[src]
impl<'_, T: ?Sized> ToBytes for Cow<'_, T> where
T: ToBytes + ToOwned,
T::Owned: ToBytes,
[src]
T: ToBytes + ToOwned,
T::Owned: ToBytes,