Skip to main content

EncodeSet

Struct EncodeSet 

Source
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

Source

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.

Source

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("...").

Source

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.

Source

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.

Source

pub const fn disallow(self, b: u8) -> EncodeSet

Returns a copy of the set that percent-encodes b.

Source

pub const fn is_allowed(&self, b: u8) -> bool

True if b passes through this set unencoded.

Trait Implementations§

Source§

impl Clone for EncodeSet

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for EncodeSet

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.