rs-urlencoding 1.0.0

A Rust library for doing URL percentage encoding.
Documentation
  • Coverage
  • 100%
    6 out of 6 items documented2 out of 2 items with examples
  • Size
  • Source code size: 18.34 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 416.6 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 2s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • smalls0098/rust_urlencoding
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • smalls0098

urlencoding

Latest Version

A tiny Rust library for doing URL percentage encoding and decoding. It percent-encodes everything except alphanumerics and -, _, ., ~.

When decoding + is not treated as a space. Error recovery from incomplete percent-escapes follows the WHATWG URL standard.

Usage

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")?;
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.

License

This project is licensed under the MIT license. For more information see the LICENSE file.