Expand description
rust literal encoders.
encodes untrusted strings for safe embedding in rust source literals.
for_rust_string— safe for rust string literals ("...")for_rust_char— safe for rust char literals ('...')for_rust_byte_string— safe for rust byte string literals (b"...")
§encoding rules
all three encoders use rust’s native escape syntax:
- named escapes:
\0,\t,\n,\r,\\ - C0 controls and DEL without named escapes →
\xHH - unicode non-characters → space (string/char) or
\xHHper byte (byte string)
the encoders differ in which quote is escaped and how non-ASCII is handled:
| encoder | quote escape | non-ASCII |
|---|---|---|
for_rust_string | " → \" | passes through |
for_rust_char | ' → \' | passes through |
for_rust_byte_string | " → \" | each UTF-8 byte → \xHH |
Functions§
- for_
rust_ byte_ string - encodes
inputfor safe embedding in a rust byte string literal (b"..."). - for_
rust_ char - encodes
inputfor safe embedding in a rust char literal ('...'). - for_
rust_ string - encodes
inputfor safe embedding in a rust string literal ("..."). - write_
rust_ byte_ string - writes the rust-byte-string-encoded form of
inputtoout. - write_
rust_ char - writes the rust-char-encoded form of
inputtoout. - write_
rust_ string - writes the rust-string-encoded form of
inputtoout.