pub trait ToUtf8Bytes {
// Required methods
fn to_utf8bytes(&self) -> Utf8Bytes;
fn to_compact_utf8bytes(&self) -> Utf8Bytes;
}alloc or std only.Expand description
Converts a value to shared or compact UTF-8 bytes using its fmt::Display implementation.
ToUtf8Bytes::to_utf8bytes returns the default shared Utf8Bytes,
which retains heap storage after shrinking. ToUtf8Bytes::to_compact_utf8bytes
returns crate::compact::Utf8Bytes, which moves short contents back to
inline storage.
§Examples
use smol_bytes::ToUtf8Bytes;
assert_eq!(42.to_utf8bytes().as_str(), "42");Required Methods§
Sourcefn to_utf8bytes(&self) -> Utf8Bytes
fn to_utf8bytes(&self) -> Utf8Bytes
Converts this value to the default shared Utf8Bytes using fmt::Display.
Shared results retain heap storage when they are later shortened. Use
ToUtf8Bytes::to_compact_utf8bytes when short results should use inline storage.
Sourcefn to_compact_utf8bytes(&self) -> Utf8Bytes
fn to_compact_utf8bytes(&self) -> Utf8Bytes
Converts this value to compact crate::compact::Utf8Bytes using fmt::Display.
Compact results use inline storage when their contents fit. Use
ToUtf8Bytes::to_utf8bytes when retaining heap storage after shrinking is preferred.
§Examples
use smol_bytes::{ToUtf8Bytes, compact};
let value: compact::Utf8Bytes = 42.to_compact_utf8bytes();
assert_eq!(value.as_str(), "42");Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".