Skip to main content

write_quoted

Function write_quoted 

Source
pub fn write_quoted(s: &[u8], out: &mut impl Sink) -> Result<(), WriteError>
Expand description

Writes s as a quoted string.

Only " and \ are escaped (RFC 9110 section 5.6.4: senders SHOULD NOT generate other quoted pairs); HTAB, SP, VCHAR, and obs-text are written as they are.

§Errors

WriteError::Forbidden for CR, LF, NUL, another control byte, or DEL; WriteError::Full.

§Examples

use parse_net::{write::write_quoted, SliceSink};

let mut buf = [0u8; 16];
let mut out = SliceSink::new(&mut buf);
write_quoted(b"a \"b\"", &mut out)?;
assert_eq!(out.written(), b"\"a \\\"b\\\"\"");