1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
pub use *;
pub use *;
/// 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.
///
/// [`encode`]: crate::PctString::encode
///
/// # Example
///
/// ```
/// use pct_str::{PctString, UriReserved};
///
/// let pct_string = PctString::encode("Hello World!".chars(), UriReserved::Any);
/// println!("{}", pct_string.as_str()); // => Hello World%21
/// ```
///
/// Custom encoder implementation:
///
/// ```
/// use pct_str::{PctString, UriReserved};
///
/// 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);
/// println!("{}", pct_string.as_str()); // => %48ello %57orld%21
/// ```