[][src]Struct byte_set::ByteSet

#[repr(transparent)]pub struct ByteSet(_);

An efficient, general-purpose set of u8s.

Implementation

This is a 256-bit mask where a byte is contained based on whether its bit is enabled. The first (least significant) bit in the mask represents the first byte in the set. Likewise, the last last (most significant) bit represents the last byte.

The mask is composed a of "chunk" array. Each chunk is either 64 or 32 bits wide, depending on the target architecture. As of right now, this is based on native register size. This may change in the future based on target features that enable better performance.

Implementations

impl ByteSet[src]

#[must_use]pub const fn new() -> Self[src]

Returns a set containing no bytes.

#[must_use]pub const fn full() -> Self[src]

Returns a set containing all bytes (0-255).

pub fn rand<R: RngCore>(rng: R) -> Self[src]

This is supported on feature="rand" or feature="rand_core" only.

Returns a set containing uniformly-distributed random bytes from rng.

This uses fill_bytes under the hood.

pub fn try_rand<R: RngCore>(rng: R) -> Result<Self, Error>[src]

This is supported on feature="rand" or feature="rand_core" only.

Returns a set containing uniformly-distributed random bytes from rng, or Err if rng failed.

This uses try_fill_bytes under the hood.

#[must_use]pub const fn is_empty(&self) -> bool[src]

Returns true if self contains no bytes.

This is more efficient than checking self.len() == 0.

#[must_use]pub const fn is_full(&self) -> bool[src]

Returns true if self contains all bytes.

This is more efficient than checking self.len() == 256.

#[must_use]pub const fn len(&self) -> usize[src]

Returns the number of bytes contained in self.

pub fn clear(&mut self)[src]

Removes all bytes from self.

pub fn first(&self) -> Option<u8>[src]

Returns the first (least) byte in self, or None if self is empty.

pub fn pop_first(&mut self) -> Option<u8>[src]

Removes the first (least) byte in self and returns it, or None if self is empty.

pub fn last(&self) -> Option<u8>[src]

Returns the last (greatest) byte in self, or None if self is empty.

pub fn pop_last(&mut self) -> Option<u8>[src]

Removes the last (least) byte in self and returns it, or None if self is empty.

pub fn insert(&mut self, byte: u8)[src]

Inserts byte into self in-place.

Unlike HashSet::insert and BTreeSet::insert, this does not return a bool for whether byte was not present. This is because it's just as efficient to call contains before.

pub fn insert_all(&mut self, other: Self)[src]

Inserts all bytes of other into self in-place.

#[must_use]pub const fn inserting(self, byte: u8) -> Self[src]

Returns a copy of self with byte inserted.

#[must_use]pub const fn inserting_all(self, other: Self) -> Self[src]

Returns a copy of self with all of other inserted.

This is equivalent to the union method.

pub fn remove(&mut self, byte: u8)[src]

Removes byte from self in-place.

Unlike HashSet::remove and BTreeSet::remove, this does not return a bool for whether byte was present. This is because it's just as efficient to call contains before.

pub fn remove_all(&mut self, other: Self)[src]

Removes all bytes of other from self in-place.

#[must_use]pub const fn removing(self, byte: u8) -> Self[src]

Returns a copy of self with byte removed.

#[must_use]pub const fn removing_all(self, other: Self) -> Self[src]

Returns a copy of self with byte removed.

pub fn set(&mut self, byte: u8, enabled: bool)[src]

Sets byte in self to enabled in-place.

#[must_use]pub const fn setting(self, byte: u8, enabled: bool) -> Self[src]

Returns a copy of self with byte set to enabled.

#[must_use]pub const fn contains(&self, byte: u8) -> bool[src]

Returns true if byte is contained in self.

#[must_use]pub fn contains_any(&self, other: &Self) -> bool[src]

Returns true if self contains any bytes in other.

#[must_use]pub fn is_subset(&self, other: &Self) -> bool[src]

Returns true if other contains all bytes in self.

#[must_use]pub fn is_strict_subset(&self, other: &Self) -> bool[src]

Returns true if other contains all bytes in self and at least one other byte not contained in self.

This is also known as a "proper subset".

#[must_use]pub fn is_superset(&self, other: &Self) -> bool[src]

Returns true if self contains all bytes in other.

#[must_use]pub fn is_strict_superset(&self, other: &Self) -> bool[src]

Returns true if self contains all bytes in other and at least one other byte not contained in other.

This is also known as a "proper superset".

#[must_use]pub fn is_disjoint(&self, other: &Self) -> bool[src]

Returns true if self and other have no bytes in common.

#[must_use]pub const fn difference(self, other: Self) -> Self[src]

Returns a set with the bytes contained in self, but not in other.

#[must_use]pub const fn symmetric_difference(self, other: Self) -> Self[src]

Returns a set with the bytes contained in self or other, but not in both.

#[must_use]pub const fn intersection(self, other: Self) -> Self[src]

Returns a set with the bytes contained both in self and other.

#[must_use]pub const fn union(self, other: Self) -> Self[src]

Returns a new set with the bytes contained in self or other.

#[must_use]pub const fn not(self) -> Self[src]

Returns a new set with the bytes not contained in self.

This exists because the Not trait cannot be used in const yet.

#[must_use]pub const fn reverse_bits(self) -> Self[src]

Returns self with its bits reversed.

This is equivalent to checking for 255 - b in all subsequent searches of b.

#[must_use]pub const fn eq(&self, other: &Self) -> bool[src]

Returns true if self and other contain the same bytes.

This exists because PartialEq is currently unstable in const.

#[must_use]pub const fn ne(&self, other: &Self) -> bool[src]

Returns true if self and other do not contain the same bytes.

This exists because PartialEq is currently unstable in const.

impl ByteSet[src]

Operations related to the ASCII character set.

pub const ASCII: Self[src]

The set of all ASCII characters: U+0000 NULL ..= U+007F DELETE.

Examples

This contains all bytes for which u8::is_ascii returns true:

for byte in ByteSet::ASCII {
    assert!(byte.is_ascii());
}

for byte in !ByteSet::ASCII {
    assert!(!byte.is_ascii());
}

pub const ASCII_ALPHABETIC: Self[src]

The set of all ASCII alphabetic characters:

  • U+0041 'A' ..= U+005A 'Z'
  • U+0061 'a' ..= U+007A 'z'

Examples

This contains all bytes for which u8::is_ascii_alphabetic returns true:

for byte in ByteSet::ASCII_ALPHABETIC {
    assert!(byte.is_ascii_alphabetic());
}

for byte in !ByteSet::ASCII_ALPHABETIC {
    assert!(!byte.is_ascii_alphabetic());
}

pub const ASCII_UPPERCASE: Self[src]

The set of all ASCII uppercase characters: U+0041 'A' ..= U+005A 'Z'.

Examples

This contains all bytes for which u8::is_ascii_uppercase returns true:

for byte in ByteSet::ASCII_UPPERCASE {
    assert!(byte.is_ascii_uppercase());
}

for byte in !ByteSet::ASCII_UPPERCASE {
    assert!(!byte.is_ascii_uppercase());
}

pub const ASCII_LOWERCASE: Self[src]

The set of all ASCII lowercase characters: U+0061 'a' ..= U+007A 'z'.

Examples

This contains all bytes for which u8::is_ascii_lowercase returns true:

for byte in ByteSet::ASCII_LOWERCASE {
    assert!(byte.is_ascii_lowercase());
}

for byte in !ByteSet::ASCII_LOWERCASE {
    assert!(!byte.is_ascii_lowercase());
}

pub const ASCII_ALPHANUMERIC: Self[src]

The set of all ASCII alphanumeric characters:

  • U+0041 'A' ..= U+005A 'Z'
  • U+0061 'a' ..= U+007A 'z'
  • U+0030 '0' ..= U+0039 '9'

Examples

This contains all bytes for which u8::is_ascii_alphanumeric returns true:

for byte in ByteSet::ASCII_ALPHANUMERIC {
    assert!(byte.is_ascii_alphanumeric());
}

for byte in !ByteSet::ASCII_ALPHANUMERIC {
    assert!(!byte.is_ascii_alphanumeric());
}

pub const ASCII_DIGIT: Self[src]

The set of all ASCII decimal digits: U+0030 '0' ..= U+0039 '9'.

Examples

This contains all bytes for which u8::is_ascii_digit returns true:

for byte in ByteSet::ASCII_DIGIT {
    assert!(byte.is_ascii_digit());
}

for byte in !ByteSet::ASCII_DIGIT {
    assert!(!byte.is_ascii_digit());
}

pub const ASCII_HEXDIGIT: Self[src]

The set of all ASCII hexadecimal digits:

  • U+0030 '0' ..= U+0039 '9'
  • U+0041 'A' ..= U+0046 'F'
  • U+0061 'a' ..= U+0066 'f'

Examples

This contains all bytes for which u8::is_ascii_hexdigit returns true:

for byte in ByteSet::ASCII_HEXDIGIT {
    assert!(byte.is_ascii_hexdigit());
}

for byte in !ByteSet::ASCII_HEXDIGIT {
    assert!(!byte.is_ascii_hexdigit());
}

pub const ASCII_PUNCTUATION: Self[src]

The set of all ASCII punctuation characters:

  • U+0021 ..= U+002F ! " # $ % & ' ( ) * + , - . /
  • U+003A ..= U+0040 : ; < = > ? @
  • U+005B ..= U+0060 [ \ ] ^ _ `
  • U+007B ..= U+007E { | } ~

Examples

This contains all bytes for which u8::is_ascii_punctuation returns true:

for byte in ByteSet::ASCII_PUNCTUATION {
    assert!(byte.is_ascii_punctuation());
}

for byte in !ByteSet::ASCII_PUNCTUATION {
    assert!(!byte.is_ascii_punctuation());
}

pub const ASCII_GRAPHIC: Self[src]

The set of all ASCII graphic characters: U+0021 '!' ..= U+007E '~'.

Examples

This contains all bytes for which u8::is_ascii_graphic returns true:

for byte in ByteSet::ASCII_GRAPHIC {
    assert!(byte.is_ascii_graphic());
}

for byte in !ByteSet::ASCII_GRAPHIC {
    assert!(!byte.is_ascii_graphic());
}

pub const ASCII_WHITESPACE: Self[src]

The set of all ASCII whitespace characters:

  • U+0020 SPACE
  • U+0009 HORIZONTAL TAB
  • U+000A LINE FEED
  • U+000C FORM FEED
  • U+000D CARRIAGE RETURN

Examples

This contains all bytes for which u8::is_ascii_whitespace returns true:

for byte in ByteSet::ASCII_WHITESPACE {
    assert!(byte.is_ascii_whitespace());
}

for byte in !ByteSet::ASCII_WHITESPACE {
    assert!(!byte.is_ascii_whitespace());
}

pub const ASCII_CONTROL: Self[src]

The set of all ASCII control characters:

  • U+0000 NUL ..= U+001F UNIT SEPARATOR
  • U+007F DELETE.

Note that most ASCII whitespace characters are control characters, but SPACE is not.

Examples

This contains all bytes for which u8::is_ascii_control returns true:

for byte in ByteSet::ASCII_CONTROL {
    assert!(byte.is_ascii_control());
}

for byte in !ByteSet::ASCII_CONTROL {
    assert!(!byte.is_ascii_control());
}

#[must_use]pub const fn is_ascii(&self) -> bool[src]

Returns true if u8::is_ascii returns true for all bytes in self.

This is significantly more efficient than checking each byte in self individually.

#[must_use]pub const fn is_ascii_alphabetic(&self) -> bool[src]

Returns true if u8::is_ascii_alphabetic returns true for all bytes in self.

This is significantly more efficient than checking each byte in self individually.

#[must_use]pub const fn is_ascii_uppercase(&self) -> bool[src]

Returns true if u8::is_ascii_uppercase returns true for all bytes in self.

This is significantly more efficient than checking each byte in self individually.

#[must_use]pub const fn is_ascii_lowercase(&self) -> bool[src]

Returns true if u8::is_ascii_lowercase returns true for all bytes in self.

This is significantly more efficient than checking each byte in self individually.

#[must_use]pub const fn is_ascii_alphanumeric(&self) -> bool[src]

Returns true if u8::is_ascii_alphanumeric returns true for all bytes in self.

This is significantly more efficient than checking each byte in self individually.

#[must_use]pub const fn is_ascii_digit(&self) -> bool[src]

Returns true if u8::is_ascii_digit returns true for all bytes in self.

This is significantly more efficient than checking each byte in self individually.

#[must_use]pub const fn is_ascii_hexdigit(&self) -> bool[src]

Returns true if u8::is_ascii_hexdigit returns true for all bytes in self.

This is significantly more efficient than checking each byte in self individually.

#[must_use]pub const fn is_ascii_punctuation(&self) -> bool[src]

Returns true if u8::is_ascii_punctuation returns true for all bytes in self.

This is significantly more efficient than checking each byte in self individually.

#[must_use]pub const fn is_ascii_graphic(&self) -> bool[src]

Returns true if u8::is_ascii_graphic returns true for all bytes in self.

This is significantly more efficient than checking each byte in self individually.

#[must_use]pub const fn is_ascii_whitespace(&self) -> bool[src]

Returns true if u8::is_ascii_whitespace returns true for all bytes in self.

This is significantly more efficient than checking each byte in self individually.

#[must_use]pub const fn is_ascii_control(&self) -> bool[src]

Returns true if u8::is_ascii_control returns true for all bytes in self.

This is significantly more efficient than checking each byte in self individually.

impl ByteSet[src]

Operations over the internal memory representation.

pub fn as_bytes(&self) -> &[u8; 32][src]

Returns a shared reference to the underlying bytes of self.

pub fn as_bytes_mut(&mut self) -> &mut [u8; 32][src]

Returns a mutable reference to the underlying bytes of self.

pub fn slice_as_bytes(slice: &[Self]) -> &[u8][src]

Returns a shared reference to the underlying bytes of slice.

pub fn slice_as_bytes_mut(slice: &mut [Self]) -> &mut [u8][src]

Returns a mutable reference to the underlying bytes of slice.

Trait Implementations

impl BitAnd<ByteSet> for ByteSet[src]

type Output = Self

The resulting type after applying the & operator.

impl BitAndAssign<ByteSet> for ByteSet[src]

impl BitOr<ByteSet> for ByteSet[src]

type Output = Self

The resulting type after applying the | operator.

impl BitOrAssign<ByteSet> for ByteSet[src]

impl BitXor<ByteSet> for ByteSet[src]

type Output = Self

The resulting type after applying the ^ operator.

impl BitXorAssign<ByteSet> for ByteSet[src]

impl Clone for ByteSet[src]

impl Copy for ByteSet[src]

impl Debug for ByteSet[src]

impl Default for ByteSet[src]

impl Distribution<ByteSet> for Standard[src]

impl Eq for ByteSet[src]

impl<'a> Extend<&'a u8> for ByteSet[src]

impl Extend<u8> for ByteSet[src]

impl<'_> From<&'_ [u8]> for ByteSet[src]

impl<'_> From<&'_ str> for ByteSet[src]

impl From<ByteSet> for Iter[src]

impl From<u8> for ByteSet[src]

impl<'a> FromIterator<&'a u8> for ByteSet[src]

impl FromIterator<u8> for ByteSet[src]

impl Hash for ByteSet[src]

impl IntoIterator for ByteSet[src]

type Item = u8

The type of the elements being iterated over.

type IntoIter = Iter

Which kind of iterator are we turning this into?

impl Not for ByteSet[src]

type Output = Self

The resulting type after applying the ! operator.

impl Ord for ByteSet[src]

impl PartialEq<ByteSet> for ByteSet[src]

impl PartialOrd<ByteSet> for ByteSet[src]

impl StructuralEq for ByteSet[src]

impl StructuralPartialEq for ByteSet[src]

impl Sub<ByteSet> for ByteSet[src]

type Output = Self

The resulting type after applying the - operator.

impl SubAssign<ByteSet> for ByteSet[src]

Auto Trait Implementations

impl RefUnwindSafe for ByteSet

impl Send for ByteSet

impl Sync for ByteSet

impl Unpin for ByteSet

impl UnwindSafe for ByteSet

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,