Skip to main content

Module rust

Module rust 

Source
Expand description

rust literal encoders.

encodes untrusted strings for safe embedding in rust source literals.

§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 \xHH per byte (byte string)

the encoders differ in which quote is escaped and how non-ASCII is handled:

encoderquote escapenon-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 input for safe embedding in a rust byte string literal (b"...").
for_rust_char
encodes input for safe embedding in a rust char literal ('...').
for_rust_string
encodes input for safe embedding in a rust string literal ("...").
write_rust_byte_string
writes the rust-byte-string-encoded form of input to out.
write_rust_char
writes the rust-char-encoded form of input to out.
write_rust_string
writes the rust-string-encoded form of input to out.