Struct IntervalSet

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

A collection of non-overlapping Unicode codepoint intervals that enables interval-based operations, such as iteration over all Unicode codepoints or finding the codepoint at a specific position within the intervals.

Implementations§

Source§

impl IntervalSet

Source

pub fn len(&self) -> usize

Returns the number of Unicode codepoints in the interval set.

§Examples
let interval_set = unicode_intervals::query()
    .include_categories(UnicodeCategory::UPPERCASE_LETTER)
    .interval_set()
    .expect("Invalid query input");
assert_eq!(interval_set.len(), 1831);
Source

pub const fn is_empty(&self) -> bool

Returns true if the interval set contains no elements.

§Examples
let interval_set = unicode_intervals::query()
    .include_categories(UnicodeCategory::UPPERCASE_LETTER)
    // The first upper case letter has 65
    .max_codepoint(50)
    .interval_set()
    .expect("Invalid query input");
assert!(interval_set.is_empty());
Source

pub fn contains(&self, codepoint: impl Into<u32>) -> bool

Returns true if the interval set contains a codepoint with the given value.

§Examples
let interval_set = unicode_intervals::query()
    .include_categories(UnicodeCategory::UPPERCASE_LETTER)
    .interval_set()
    .expect("Invalid query input");
assert!(interval_set.contains('C'));
assert!(!interval_set.contains('a'));
Source

pub fn codepoint_at(&self, index: u32) -> Option<u32>

Returns the codepoint at index in the IntervalSet.

§Examples
let interval_set = unicode_intervals::query()
    .include_categories(UnicodeCategory::UPPERCASE_LETTER)
    .interval_set()
    .expect("Invalid query input");
// Get 10th codepoint in this interval set
assert_eq!(interval_set.codepoint_at(10), Some('K' as u32));
Source

pub fn index_of(&self, codepoint: impl Into<u32>) -> Option<u32>

Returns the index of a specific codepoint in the IntervalSet.

§Examples
let interval_set = unicode_intervals::query()
    .include_categories(UnicodeCategory::UPPERCASE_LETTER)
    .interval_set()
    .expect("Invalid query input");
assert_eq!(interval_set.index_of('A'), Some(0));
assert_eq!(interval_set.index_of('c'), None);
Source

pub fn index_above(&self, codepoint: impl Into<u32>) -> u32

Returns the index of a specific codepoint in the IntervalSet if it is present in the set, or the index of the closest codepoint that is greater than the given one.

If the given codepoint is greater than the largest codepoint in the set, then the set’s size is returned.

§Examples
let interval_set = unicode_intervals::query()
    .include_categories(UnicodeCategory::UPPERCASE_LETTER)
    .interval_set()
    .expect("Invalid query input");
assert_eq!(interval_set.index_above('Z'), 25);
Source

pub fn iter(&self) -> impl Iterator<Item = u32> + DoubleEndedIterator + '_

Returns an iterator over all codepoints in all contained intervals.

§Examples
let interval_set = unicode_intervals::query()
    .include_categories(UnicodeCategory::UPPERCASE_LETTER)
    .max_codepoint(67)
    .interval_set()
    .expect("Invalid query input");
let mut iterator = interval_set.iter();
assert_eq!(iterator.next(), Some('A' as u32));
assert_eq!(iterator.next(), Some('B' as u32));
assert_eq!(iterator.next(), Some('C' as u32));
assert_eq!(iterator.next(), None);

Trait Implementations§

Source§

impl Clone for IntervalSet

Source§

fn clone(&self) -> IntervalSet

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

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

Performs copy-assignment from source. Read more
Source§

impl Debug for IntervalSet

Source§

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

Formats the value using the given formatter. 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> 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.