Struct CharSet

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

Interval [start, end] where start <= end <= MAX_CHAR.

This represents a range of characters.

Implementations§

Source§

impl CharSet

Source

pub fn singleton(x: u32) -> CharSet

Construct the singleton interval [x, x]

  • the integer x must be a valid SMT-LIB character (i.e., 0 <= x <= MAX_CHAR)
Source

pub fn range(x: u32, y: u32) -> CharSet

Construct the interval [x, y]

Source

pub fn all_chars() -> CharSet

Construct the interval [0, MAX_CHAR]

Source

pub fn contains(&self, x: u32) -> bool

Check whether x is in this interval

§Example
use aws_smt_strings::character_sets::CharSet;

let c = CharSet::range('a' as u32, 'z' as u32);
assert!(c.contains('g' as u32));
assert!(!c.contains('0' as u32));
Source

pub fn covers(&self, other: &CharSet) -> bool

Check whether other is a subset of this set

§Example
use aws_smt_strings::character_sets::CharSet;

let c = CharSet::range('a' as u32, 'z' as u32);
assert!(c.covers(&CharSet::singleton('g' as u32)));
assert!(c.covers(&CharSet::range('t' as u32, 'z' as u32)));
assert!(! c.covers(&CharSet::range(0, 'k' as u32)));
Source

pub fn is_before(&self, x: u32) -> bool

Check whether this set is before x

If set is [a, b] this checks whether b < x.

§Example
use aws_smt_strings::character_sets::CharSet;

let c = CharSet::range('a' as u32, 'z' as u32);
assert!(c.is_before(127));
assert!(! c.is_before('c' as u32));
Source

pub fn is_after(&self, x: u32) -> bool

Check whether this set is after x

If set is the interval [a, b], this checks whether x < a.

§Example
use aws_smt_strings::character_sets::CharSet;

let c = CharSet::range('a' as u32, 'z' as u32);
assert!(! c.is_after(127));
assert!(c.is_after('Z' as u32));
Source

pub fn size(&self) -> u32

Get the size of this set

Return the number of characters in the interval

§Example
use aws_smt_strings::character_sets::CharSet;

let c = CharSet::range('a' as u32, 'z' as u32);
assert_eq!(c.size(), 26);
Source

pub fn is_singleton(&self) -> bool

Check whether the set is a singleton

§Example
use aws_smt_strings::character_sets::CharSet;

let c = CharSet::range('a' as u32, 'z' as u32);
let d = CharSet::singleton('K' as u32);
assert!(d.is_singleton());
assert!(! c.is_singleton());
Source

pub fn is_alphabet(&self) -> bool

Check whether this set is the full alphabet

§Example
use aws_smt_strings::{character_sets::CharSet, smt_strings::MAX_CHAR};

let c = CharSet::range(0, MAX_CHAR);
let d = CharSet::range('a' as u32, 'z' as u32);
assert!(c.is_alphabet());
assert!(! d.is_alphabet());
Source

pub fn pick(&self) -> u32

Pick a character in the set

§Example
use aws_smt_strings::character_sets::CharSet;

let c = CharSet::range('a' as u32, 'z' as u32);
let d = c.pick();
assert!('a' as u32 <= d && d <= 'z' as u32);
Source

pub fn inter(&self, other: &CharSet) -> Option<CharSet>

Intersection of two intervals

  • return None if the intersection is empty
  • return Some(charset) otherwise.
§Example
use aws_smt_strings::character_sets::CharSet;

let c = CharSet::range('a' as u32, 'z' as u32); // ['a', 'z']
let d = CharSet::range('t' as u32, 127);  // ['t', 127]

// the intersection of c and d is ['t', 'z']
assert_eq!(c.inter(&d), Some(CharSet::range('t' as u32, 'z' as u32)));
Source

pub fn inter_list(a: &[CharSet]) -> Option<CharSet>

Intersection of an array of intervals

See inter

  • return None if the intersection is empty
  • return Some(c) otherwise
Source

pub fn union(&self, other: &CharSet) -> Option<CharSet>

Union of two intervals

  • return None if the union is not an interval
  • return Some(c) where c is a CharSet otherwise.
§Example
use aws_smt_strings::character_sets::CharSet;

let c = CharSet::range('a' as u32, 'z' as u32);
let d = CharSet::range('t' as u32, 127);
let e = CharSet::range('0' as u32, '9' as u32);

assert_eq!(c.union(&d), Some(CharSet::range('a' as u32, 127)));
assert_eq!(c.union(&e), None);

Trait Implementations§

Source§

impl Clone for CharSet

Source§

fn clone(&self) -> CharSet

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 CharSet

Source§

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

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

impl Display for CharSet

Source§

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

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

impl Hash for CharSet

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 CharSet

Source§

fn eq(&self, other: &CharSet) -> 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 PartialOrd for CharSet

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for CharSet

Source§

impl Eq for CharSet

Source§

impl StructuralPartialEq for CharSet

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.