CharsetSpec

Struct CharsetSpec 

Source
pub struct CharsetSpec { /* private fields */ }
Expand description

Represents a specification for a charset

Any of the predefined CharsetNames can be toggled and additional characters may be included. For this purpose, CharsetSpec implements AddAssign<CharsetName> and SubAssign<CharsetName>. Alternatively, you can parse a string containing the corresponding chars.

§Example

let mut spec = yapg::CharsetSpec::empty();
spec += yapg::CharsetName::Numeric; // Adding a named charset
spec += "+-*"; // Adding a string
spec += '/'; // Adding a single char

assert_eq!(spec.construct().as_slice(), [
    '*', '+', '-', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
]);

Implementations§

Source§

impl CharsetSpec

Source

pub fn construct(self) -> Vec<char>

Builds the actual character set in form of a Vec<char>, which is sorted and deduplicated.

Source

pub fn empty() -> Self

Creates the specification for an empty charset.

§Example
let charset = yapg::CharsetSpec::empty().construct();
assert_eq!(charset.len(), 0);
Source

pub fn std64() -> Self

Creates the specification for a standard charset, including all alphanumerics, - and _. Should be safe to use in most places, except for strict “no-special-characters”-policies or where neither - nor _ are considered to be special, yet special chars are required.

§Example
let charset = yapg::CharsetSpec::std64().construct();
assert_eq!(charset.len(), 64);
Source

pub fn printable_ascii() -> Self

Creates the specification for charset that contains all printable ASCII characters.

§Example
let charset = yapg::CharsetSpec::printable_ascii().construct();
assert_eq!(charset.len(), 95);

Trait Implementations§

Source§

impl AddAssign<&str> for CharsetSpec

Source§

fn add_assign(&mut self, more: &str)

Performs the += operation. Read more
Source§

impl AddAssign<CharsetName> for CharsetSpec

Source§

fn add_assign(&mut self, name: CharsetName)

Performs the += operation. Read more
Source§

impl AddAssign<char> for CharsetSpec

Source§

fn add_assign(&mut self, c: char)

Performs the += operation. Read more
Source§

impl Debug for CharsetSpec

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FromStr for CharsetSpec

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self>

Parses a string s to return a value of this type. Read more
Source§

impl Into<Vec<char>> for CharsetSpec

Source§

fn into(self) -> Vec<char>

Converts this type into the (usually inferred) input type.
Source§

impl SubAssign<CharsetName> for CharsetSpec

Source§

fn sub_assign(&mut self, name: CharsetName)

Performs the -= operation. Read more

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.