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
impl CharsetSpec
Sourcepub fn construct(self) -> Vec<char>
pub fn construct(self) -> Vec<char>
Builds the actual character set in form of a Vec<char>, which is
sorted and deduplicated.
Sourcepub fn empty() -> Self
pub fn empty() -> Self
Creates the specification for an empty charset.
§Example
let charset = yapg::CharsetSpec::empty().construct();
assert_eq!(charset.len(), 0);Sourcepub fn std64() -> Self
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);Sourcepub fn printable_ascii() -> Self
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
impl AddAssign<&str> for CharsetSpec
Source§fn add_assign(&mut self, more: &str)
fn add_assign(&mut self, more: &str)
+= operation. Read moreSource§impl AddAssign<CharsetName> for CharsetSpec
impl AddAssign<CharsetName> for CharsetSpec
Source§fn add_assign(&mut self, name: CharsetName)
fn add_assign(&mut self, name: CharsetName)
+= operation. Read moreSource§impl AddAssign<char> for CharsetSpec
impl AddAssign<char> for CharsetSpec
Source§fn add_assign(&mut self, c: char)
fn add_assign(&mut self, c: char)
+= operation. Read moreSource§impl Debug for CharsetSpec
impl Debug for CharsetSpec
Source§impl FromStr for CharsetSpec
impl FromStr for CharsetSpec
Source§impl SubAssign<CharsetName> for CharsetSpec
impl SubAssign<CharsetName> for CharsetSpec
Source§fn sub_assign(&mut self, name: CharsetName)
fn sub_assign(&mut self, name: CharsetName)
-= operation. Read more