Struct AsciiSet

Source
pub struct AsciiSet {
    pub lo_mask: u64,
    pub hi_mask: u64,
}
Expand description

Provides a fast method for testing character membership of a purely ASCII set.

This is implemented as a bitset, and will therefore always use 16 bytes, no matter how many characters the set contains.

Fields§

§lo_mask: u64

The bitmask representing characters 0 through 63. If c <= 63 and (lo_mask >> c) & 1 == 1 then the ASCII codepoint c belongs to this set.

§hi_mask: u64

The bitmask representing characters 64 through 127.

Implementations§

Source§

impl AsciiSet

Source

pub fn contains_char(&self, c: char) -> bool

Tests whether this set contains the char c.

Source

pub fn contains_byte(&self, c: u8) -> bool

Tests whether this set contains the byte c.

Source

pub fn insert_byte(&mut self, c: u8)

Adds a byte to this set.

§Panics
  • if c falls outside the ASCII range.
Source

pub fn insert_char(&mut self, c: char)

Adds a char to this set.

§Panics
  • if c falls outside the ASCII range.
Source

pub fn new() -> AsciiSet

Creates a new, empty, AsciiSet.

Source

pub fn from_ranges<I>(iter: I) -> AsciiSet
where I: IntoIterator<Item = (char, char)>,

Builds an AsciiSet as a union of ranges (which are inclusive).

§Panics
  • if any of the ranges overlap anything outside the ASCII range.
§Examples
use ascii_set::AsciiSet;
let a = AsciiSet::from_ranges(vec![('a', 'e'), ('A', 'E')]);
assert!(a.contains_char('a'));
assert!(a.contains_char('b'));
assert!(a.contains_char('e'));
assert!(!a.contains_char('f'));
Source

pub fn from_fn<F>(f: F) -> AsciiSet
where F: FnMut(char) -> bool,

Builds the AsciiSet consisting of all characters for which f returns true.

§Examples
use ascii_set::AsciiSet;
assert_eq!(
    AsciiSet::from_ranges(vec![('a', 'z'), ('A', 'Z')]),
    AsciiSet::from_fn(|c| c.is_alphabetic()));
Source

pub fn from_chars<I>(iter: I) -> AsciiSet
where I: IntoIterator<Item = char>,

Builds the AsciiSet consisting of all characters yielded by iter.

§Panics
  • if iter yields any non-ASCII characters.
§Examples
use ascii_set::AsciiSet;
assert_eq!(
    AsciiSet::from_ranges(vec![('a', 'z')]),
    AsciiSet::from_chars("abcdefghijklmnopqrstuvwxyz".chars()));
Source

pub fn union(&self, other: &AsciiSet) -> AsciiSet

Returns the union of this set and other.

§Examples
use ascii_set::AsciiSet;
assert_eq!(
    AsciiSet::letters(),
    AsciiSet::upper_case_letters().union(&AsciiSet::lower_case_letters()));
Source

pub fn intersection(&self, other: &AsciiSet) -> AsciiSet

Returns the intersection of this set and other.

§Examples
use ascii_set::AsciiSet;
assert_eq!(
    AsciiSet::lower_case_letters(),
    AsciiSet::letters().intersection(&AsciiSet::lower_case_letters()));
Source

pub fn difference(&self, other: &AsciiSet) -> AsciiSet

Returns the set of chars in self but not other.

§Examples
use ascii_set::AsciiSet;
assert_eq!(
    AsciiSet::lower_case_letters(),
    AsciiSet::letters().difference(&AsciiSet::upper_case_letters()));
Source

pub fn complement(&self) -> AsciiSet

Returns the set of all ASCII chars not in self.

Source

pub fn lower_case_letters() -> AsciiSet

Returns the set of all lower case letters.

Source

pub fn upper_case_letters() -> AsciiSet

Returns the set of all upper case letters.

Source

pub fn letters() -> AsciiSet

Returns the set of all letters.

Source

pub fn digits() -> AsciiSet

Returns the set of all digits.

Trait Implementations§

Source§

impl Clone for AsciiSet

Source§

fn clone(&self) -> AsciiSet

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for AsciiSet

Source§

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

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

impl Hash for AsciiSet

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for AsciiSet

Source§

fn eq(&self, other: &AsciiSet) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for AsciiSet

Source§

impl StructuralPartialEq for AsciiSet

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 = 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.