[][src]Function enc::percent::encode

pub fn encode(data: &[u8], non_specials: &[u8], target: &mut [u8]) -> usize

Encodes the data into the target. Returns the length of the encoded data. This function is consistent with the encoded_length function.

Panics

This function will panic if the target has insufficient space for the encoded data.

use enc::percent::encode;

let target: &mut [u8] = &mut [0u8; 6];
let ns: &[u8] = &[b'_'];

assert_eq!(encode(&[0u8; 0], ns, target), 0);

assert_eq!(encode(&[b'a'], ns, target), 1);
assert_eq!(target[..1], [b'a']);

assert_eq!(encode(&[b'a', b'_', 0u8], ns, target), 5);
assert_eq!(target[..5], [b'a', b'_', b'%', b'0', b'0']);