pub struct EncodeSet { /* private fields */ }Expand description
A const-buildable set of ASCII bytes allowed to pass through
percent-encoding unchanged; every other byte is encoded as %XX.
Start from a base set and refine it with allow /
disallow in const context:
use safehtml::{EncodeSet, percent_encode_to};
// Path segments: unreserved characters plus a few sub-delimiters.
const PATH_SEGMENT: EncodeSet = EncodeSet::UNRESERVED.allow_all(b"!$&'()*+,;=:@");
let mut out = String::new();
percent_encode_to("a b:c/d", &PATH_SEGMENT, &mut out).unwrap();
assert_eq!(out, "a%20b:c%2Fd");Implementations§
Source§impl EncodeSet
impl EncodeSet
Sourcepub const UNRESERVED: EncodeSet
pub const UNRESERVED: EncodeSet
Only the RFC 3986 unreserved characters pass through: ASCII
alphanumerics and -, ., _, ~. The strictest base set, used by
url_encode_component_to.
Sourcepub const CSS_URL: EncodeSet
pub const CSS_URL: EncodeSet
The set used by percent_escape_css_url_to: unreserved plus the
RFC 3986 reserved characters that are safe inside CSS url("...").
Sourcepub const fn allow(self, b: u8) -> EncodeSet
pub const fn allow(self, b: u8) -> EncodeSet
Returns a copy of the set that additionally passes b through.
§Panics
Panics (at compile time in const context) if b is not ASCII:
allowing a non-ASCII byte through could split multi-byte UTF-8
characters in the output.
Sourcepub const fn allow_all(self, bytes: &[u8]) -> EncodeSet
pub const fn allow_all(self, bytes: &[u8]) -> EncodeSet
Returns a copy of the set that additionally passes every byte in
bytes through. Panics like allow on
non-ASCII bytes.
Sourcepub const fn disallow(self, b: u8) -> EncodeSet
pub const fn disallow(self, b: u8) -> EncodeSet
Returns a copy of the set that percent-encodes b.
Sourcepub const fn is_allowed(&self, b: u8) -> bool
pub const fn is_allowed(&self, b: u8) -> bool
True if b passes through this set unencoded.