pub trait WtfEncoding {
type Unit: Copy + Ord + Hash + Debug;
const NUL: Self::Unit;
// Required methods
fn encode_str(s: &str) -> Vec<Self::Unit>;
fn decode(units: &[Self::Unit]) -> Option<String>;
fn decode_lossy(units: &[Self::Unit]) -> String;
// Provided methods
fn eq_str(units: &[Self::Unit], s: &str) -> bool { ... }
fn debug_fmt(units: &[Self::Unit], f: &mut Formatter<'_>) -> Result { ... }
}Expand description
A code-unit encoding for a WtfString / WtfStr.
This trait is the storage-width seam: the API common to every width is written
against E: WtfEncoding, while width-specific API (such as the *const u16
FFI surface) lives in inherent impls on the concrete instantiations. The two
shipped encodings are Wtf16 (u16 units) and Wtf8 (u8 units); each
defines its own encode/decode/comparison/formatting semantics over a
crate-owned Vec<Unit> with the same always-terminated model.
Required Associated Constants§
Required Associated Types§
Required Methods§
Sourcefn encode_str(s: &str) -> Vec<Self::Unit>
fn encode_str(s: &str) -> Vec<Self::Unit>
Encode a UTF-8 str into this encoding’s code units.
Sourcefn decode(units: &[Self::Unit]) -> Option<String>
fn decode(units: &[Self::Unit]) -> Option<String>
Decode content code units to a String if they are well-formed for this
encoding, or None if they are ill-formed (e.g. an unpaired surrogate),
which a strict String cannot represent.
Sourcefn decode_lossy(units: &[Self::Unit]) -> String
fn decode_lossy(units: &[Self::Unit]) -> String
Decode content code units to a String, replacing any ill-formed sequence
with the Unicode replacement character (U+FFFD).
Provided Methods§
Sourcefn eq_str(units: &[Self::Unit], s: &str) -> bool
fn eq_str(units: &[Self::Unit], s: &str) -> bool
Whether content code units equal the UTF-8 str s under this encoding.
The default encodes s and compares slices; an encoding can override with
an allocation-free lazy comparison (as Wtf16 does).
Sourcefn debug_fmt(units: &[Self::Unit], f: &mut Formatter<'_>) -> Result
fn debug_fmt(units: &[Self::Unit], f: &mut Formatter<'_>) -> Result
Write the escaped debug form of units, like OsStr:
quoted, with control and non-printable characters escaped.
The default decodes lossily and escapes; an encoding can override to also
escape ill-formed sequences losslessly (as Wtf16 does for a lone
surrogate), so distinct ill-formed inputs remain distinguishable.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".