Skip to main content

encode

Function encode 

Source
pub fn encode(
    input: &[u8],
    set: &EncodeSet,
    case: HexCase,
    out: &mut impl Sink,
) -> Result<(), WriteError>
Expand description

Writes input with every byte in set, and every byte above 0x7F, as %XX.

§Errors

WriteError::Full; nothing is written when the sink reports its room.

§Examples

use parse_net::{pct::{encode, EncodeSet, HexCase}, SliceSink};

let mut buf = [0u8; 16];
let mut out = SliceSink::new(&mut buf);
encode("caf\u{e9}".as_bytes(), &EncodeSet::SF_DISPLAY, HexCase::Lower, &mut out).expect("room");
assert_eq!(out.written(), b"caf%c3%a9");