Skip to main content

Module write

Module write 

Source
Expand description

Output: the Sink trait, SliceSink, CountSink, and the writers for numbers, tokens, quoted strings, parameters, and field values.

Every writer validates all of its input before the first put, and checks remaining when its output takes several put calls, so after any error a SliceSink holds exactly what it held before. No writer can emit CR, LF, or NUL, and no writer produces a value its own parser would refuse.

§Examples

use parse_net::{self as pn, write};

let mut buf = [0u8; 64];
let mut out = pn::SliceSink::new(&mut buf);
write::write_word(b"gzip", &mut out)?;
write::write_param(b"title", b"say \"hi\"", &mut out)?;
assert_eq!(out.written(), b"gzip; title=\"say \\\"hi\\\"\"");
assert_eq!(write::write_quoted(b"a\nb", &mut out), Err(pn::WriteError::Forbidden { at: 1 }));

Structs§

CountSink
A sink that counts bytes and writes nothing.
Full
A sink has no room for the bytes it was given.
SliceSink
A cursor over a caller buffer.

Traits§

Sink
The output abstraction every writer takes.

Functions§

write_decimal_u64
Writes n in decimal, with no sign and no padding.
write_field_value
Writes s as a field value, after checking every byte is field-vchar, SP, HTAB, or obs-text.
write_hex_u64
Writes n in lowercase hexadecimal, with no prefix and no padding.
write_param
Writes ; name=value, the value through write_word.
write_quoted
Writes s as a quoted string.
write_token
Writes s as a token, after checking it is one.
write_word
Writes s as a token when it is a non-empty token, and as a quoted string otherwise (token / quoted-string, RFC 9110 section 5.6.6).