pub fn write_element(
e: &Element<'_>,
out: &mut impl Sink,
) -> Result<(), WriteError>Expand description
Writes one Forwarded element: for, proto, by, and host, in that
order, each when present, with IPv6 addresses and nodes with ports
quoted. For proxies that append their hop.
§Errors
WriteError::NotToken for an obfuscated name or port that is not _
followed by ALPHA / DIGIT / "." / "_" / "-"; WriteError::Full
(nothing written when the sink reports its room).
§Examples
use core::net::IpAddr;
use parse_net::{forwarded::{self, Element, Node, NodePort, Proto}, SliceSink};
let e = Element {
for_: Some(Node::Addr("192.0.2.60".parse::<IpAddr>()?, None)),
by: Some(Node::Addr("2001:db8::17".parse::<IpAddr>()?, Some(NodePort::Number(4711)))),
host: None,
proto: Some(Proto::Https),
};
let mut buf = [0u8; 96];
let mut out = SliceSink::new(&mut buf);
forwarded::write_element(&e, &mut out)?;
assert_eq!(out.written(), b"for=192.0.2.60;proto=https;by=\"[2001:db8::17]:4711\"");