[−][src]Trait pct_str::Encoder
Encoding predicate.
Instances of this trait are used along with the encode
function
to decide which character must be percent-encoded.
This crate provides a simple implementation of the trait, URIReserved
encoding characters reserved in the URI syntax.
Example
let pct_string = PctString::encode("Hello World!".chars(), URIReserved); println!("{}", pct_string.as_str()); // => Hello World%21
Custom encoder implementation:
struct CustomEncoder; impl pct_str::Encoder for CustomEncoder { fn encode(&self, c: char) -> bool { URIReserved.encode(c) || c.is_uppercase() } } let pct_string = PctString::encode("Hello World!".chars(), CustomEncoder); println!("{}", pct_string.as_str()); // => %48ello %57orld%21
Required methods
fn encode(&self, c: char) -> bool
Decide if the given character must be encoded.
Note that the character %
is always encoded even if this method returns false
on it.
Only characters with codepoint below 0x100
are encoded.