[][src]Trait print_bytes::ToBytes

pub trait ToBytes {
#[must_use]    pub fn to_bytes(&self) -> Bytes<'_>;
}

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]pub fn to_bytes(&self) -> Bytes<'_>[src]

Creates a byte sequence that will be used to represent the instance.

Loading content...

Implementations on Foreign Types

impl ToBytes for [u8][src]

impl<const N: usize> ToBytes for [u8; N][src]

This is supported on crate feature min_const_generics only.

impl<T: ?Sized, '_> ToBytes for Cow<'_, T> where
    T: ToBytes + ToOwned,
    T::Owned: ToBytes
[src]

impl ToBytes for OsStr[src]

impl ToBytes for CStr[src]

impl ToBytes for CString[src]

impl<'_> ToBytes for IoSlice<'_>[src]

impl<'_> ToBytes for IoSliceMut<'_>[src]

impl ToBytes for OsString[src]

impl ToBytes for Path[src]

impl ToBytes for PathBuf[src]

impl ToBytes for Vec<u8>[src]

Loading content...

Implementors

Loading content...