Crate rs_urlencoding

Source
Expand description

To encode a string, do the following:

use urlencoding::encode;

let encoded = encode("This string will be URL encoded.");
println!("{}", encoded);
// This%20string%20will%20be%20URL%20encoded.

To decode a string, it’s only slightly different:

use urlencoding::decode;

let decoded = decode("%F0%9F%91%BE%20Exterminate%21").expect("UTF-8");
println!("{}", decoded);
// 👾 Exterminate!

To decode allowing arbitrary bytes and invalid UTF-8:

use urlencoding::decode_binary;

let binary = decode_binary(b"%F1%F2%F3%C0%C1%C2");
let decoded = String::from_utf8_lossy(&binary);

This library returns Cow to avoid allocating when decoding/encoding is not needed. Call .into_owned() on the Cow to get a Vec or String.

Structs§

  • Wrapper type that implements Display. Encodes on the fly, without allocating. Percent-encodes every byte except alphanumerics and -, _, ., ~. Assumes UTF-8 encoding.

Functions§

  • Decode percent-encoded string assuming UTF-8 encoding.
  • Decode percent-encoded string as binary data, in any encoding.
  • Percent-encodes every byte except alphanumerics and -, _, ., ~. Assumes UTF-8 encoding.
  • Percent-encodes every byte except alphanumerics and -, _, ., ~.