pub trait EncodeUtf8: Sailed {
type Buf: Default;
// Required method
fn encode_utf8<'a>(&'a self, buf: &'a mut Self::Buf) -> &'a str;
}Expand description
The EncodeUtf8 trait provides a consistent interface for encoding different text-like types, making
them easily interchangeable as inputs for functions requiring UTF-8 encoded data.
This trait is designed to be implemented by types that can produce a UTF-8 string representation, enabling
functions in other traits (e.g., StrExt and StringExt) to accept a variety of text-like inputs, thus
enhancing usability by abstracting over &str, String, and char values seamlessly.
§Examples
use string_more::EncodeUtf8;
let input = 'x';
let mut buffer: [u8; 4] = Default::default();
let encoded = input.encode_utf8(&mut buffer);
assert_eq!(encoded, "x");Required Associated Types§
Required Methods§
Sourcefn encode_utf8<'a>(&'a self, buf: &'a mut Self::Buf) -> &'a str
fn encode_utf8<'a>(&'a self, buf: &'a mut Self::Buf) -> &'a str
Encodes self as a UTF-8 string and writes it into the provided mutable buf.
Returns a &str slice from the buffer that represents the encoded UTF-8 data.