Watch
1
0
Fork
You've already forked rust-pct-str
0
No description
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Daniel Baumann 7ee9dff22b
Updating to debhelper 14.
Signed-off-by: Daniel Baumann <daniel@debian.org>
2026-06-14 12:50:40 +02:00
.github/workflows Adding upstream version 2.0.0. 2025-12-31 10:48:02 +01:00
debian Updating to debhelper 14. 2026-06-14 12:50:40 +02:00
examples Merging upstream version 3.0.1. 2026-02-27 08:47:51 +01:00
src Merging upstream version 3.0.1. 2026-02-27 08:47:51 +01:00
.cargo_vcs_info.json Merging upstream version 3.0.1. 2026-02-27 08:47:51 +01:00
.gitignore Adding upstream version 2.0.0. 2025-12-31 10:48:02 +01:00
Cargo.lock Merging upstream version 3.0.1. 2026-02-27 08:47:51 +01:00
Cargo.toml Merging upstream version 3.0.1. 2026-02-27 08:47:51 +01:00
Cargo.toml.orig Merging upstream version 3.0.1. 2026-02-27 08:47:51 +01:00
LICENSE-APACHE Adding upstream version 2.0.0. 2025-12-31 10:48:02 +01:00
LICENSE-MIT Adding upstream version 2.0.0. 2025-12-31 10:48:02 +01:00
README.md Merging upstream version 3.0.1. 2026-02-27 08:47:51 +01:00
rustfmt.toml Adding upstream version 2.0.0. 2025-12-31 10:48:02 +01:00

Percent-Encoded Strings for Rust

Build Crate informations License Documentation

This crate provides two types, PctStr and PctString, similar to str and String, representing percent-encoded strings used in URL, URI, IRI, etc. You can use them to encode, decode and compare percent-encoded strings.

Basic usage

You can parse/decode percent-encoded strings by building a PctStr slice over a str slice.

use pct_str::PctStr;

let pct_str = PctStr::new("Hello%20World%21").unwrap();
assert_eq!(pct_str, "Hello World!");

let decoded_string: String = pct_str.decode();
assert_eq!(decoded_string, "Hello World!")

To create new percent-encoded strings, use the PctString to copy or encode new strings.

use pct_str::{PctString, UriReserved};

// Copy the given percent-encoded string.
let pct_string = PctString::new("Hello%20World%21").unwrap();

// Encode the given regular string.
let pct_string = PctString::encode("Hello World!".chars(), UriReserved::Any);

assert_eq!(pct_string.as_str(), "Hello%20World%21");

You can choose which character will be percent-encoded by the encode function by implementing the Encoder trait.

use pct_str::{UriReserved, PctString};

struct CustomEncoder;

impl pct_str::Encoder for CustomEncoder {
  fn encode(&self, c: char) -> bool {
    UriReserved::Any.encode(c) || c.is_uppercase()
  }
}

let pct_string = PctString::encode("Hello World!".chars(), CustomEncoder);
assert_eq!(pct_string.as_str(), "%48ello%20%57orld%21")

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.