Skip to main content

write_escaped

Function write_escaped 

Source
pub fn write_escaped(f: &mut Formatter<'_>, bytes: &[u8]) -> Result
Expand description

Writes bytes to f, rendering valid UTF-8 verbatim and every byte that is not part of a valid UTF-8 sequence as a \xHH hex escape.

PHP source is binary-safe, so identifiers, comments, and string literals can carry arbitrary bytes. When such content reaches a diagnostic message, lossy decoding would collapse every stray byte to U+FFFD — unreadable, and ambiguous (two distinct byte sequences look identical). Escaping instead keeps the output readable and lossless: Caf followed by the bytes C9 E9 FF renders as Caf\xC9\xE9\xFF.

§Errors

Returns any error produced by the underlying fmt::Formatter while writing.