unic_char_range

Struct CharRange

Source
pub struct CharRange {
    pub low: char,
    pub high: char,
}
Expand description

A range of unicode code points.

The most idiomatic way to construct this range is through the use of the chars! macro:

#[macro_use] extern crate unic_char_range;
use unic_char_range::CharRange;

assert_eq!(chars!('a'..='z'), CharRange::closed('a', 'z'));
assert_eq!(chars!('a'..'z'), CharRange::open_right('a', 'z'));
assert_eq!(chars!(..), CharRange::all());

If constructed in reverse order, such that self.high is ordered before self.low, the range is empty. If you want to iterate in decreasing order, use .iter().rev(). All empty ranges are considered equal no matter the internal state.

Fields§

§low: char

The lowest character in this range (inclusive).

§high: char

The highest character in this range (inclusive).

Implementations§

Source§

impl CharRange

Constructors

Source

pub fn closed(start: char, stop: char) -> CharRange

Construct a closed range of characters.

If stop is ordered before start, the resulting range will be empty.

§Example
assert_eq!(
    CharRange::closed('a', 'd').iter().collect::<Vec<_>>(),
    vec!['a', 'b', 'c', 'd']
)
Source

pub fn open_right(start: char, stop: char) -> CharRange

Construct a half open (right) range of characters.

§Example
assert_eq!(
    CharRange::open_right('a', 'd').iter().collect::<Vec<_>>(),
    vec!['a', 'b', 'c']
)
Source

pub fn open_left(start: char, stop: char) -> CharRange

Construct a half open (left) range of characters.

§Example
assert_eq!(
    CharRange::open_left('a', 'd').iter().collect::<Vec<_>>(),
    vec!['b', 'c', 'd']
)
Source

pub fn open(start: char, stop: char) -> CharRange

Construct a fully open range of characters.

§Example
assert_eq!(
    CharRange::open('a', 'd').iter().collect::<Vec<_>>(),
    vec!['b', 'c']
)
Source

pub fn all() -> CharRange

Construct a range over all Unicode characters (Unicode Scalar Values).

Source

pub fn assigned_normal_planes() -> CharRange

Construct a range over all characters of assigned Unicode Planes.

Assigned normal (non-special) Unicode Planes are:

  • Plane 0: Basic Multilingual Plane (BMP)
  • Plane 1: Supplementary Multilingual Plane (SMP)
  • Plane 2: Supplementary Ideographic Plane (SIP)

Unicode Plane 14, Supplementary Special-purpose Plane (SSP), is not included in this range, mainly because of the limit of CharRange only supporting a continuous range.

Unicode Planes 3 to 13 are Unassigned planes and therefore excluded.

Unicode Planes 15 and 16 are Private Use Area planes and won’t have Unicode-assigned characters.

Source§

impl CharRange

Collection-like fns

Source

pub fn contains(&self, ch: char) -> bool

Does this range include a character?

§Examples
assert!(   CharRange::closed('a', 'g').contains('d'));
assert!( ! CharRange::closed('a', 'g').contains('z'));

assert!( ! CharRange:: open ('a', 'a').contains('a'));
assert!( ! CharRange::closed('z', 'a').contains('g'));
Source

pub fn cmp_char(&self, ch: char) -> Ordering

Determine the ordering of this range and a character.

§Panics

Panics if the range is empty. This fn may be adjusted in the future to not panic in optimized builds. Even if so, an empty range will never compare as Ordering::Equal.

Source

pub fn len(&self) -> usize

How many characters are in this range?

Source

pub fn is_empty(&self) -> bool

Is this range empty?

Source

pub fn iter(&self) -> CharIter

Create an iterator over this range.

Examples found in repository?
examples/macro_use_std_tests.rs (line 16)
14
15
16
17
18
fn main() {
    assert!(chars!('\u{0}'..='\u{2}')
        .iter()
        .eq(['\u{0}', '\u{1}', '\u{2}'].iter().cloned()));
}

Trait Implementations§

Source§

impl Clone for CharRange

Source§

fn clone(&self) -> CharRange

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 CharRange

Source§

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

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

impl From<CharIter> for CharRange

Source§

fn from(iter: CharIter) -> CharRange

Converts to this type from the input type.
Source§

impl From<CharRange> for CharIter

Source§

fn from(range: CharRange) -> CharIter

Converts to this type from the input type.
Source§

impl IntoIterator for CharRange

Source§

type IntoIter = CharIter

Which kind of iterator are we turning this into?
Source§

type Item = char

The type of the elements being iterated over.
Source§

fn into_iter(self) -> CharIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for CharRange

Source§

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

Source§

impl Eq for CharRange

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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, 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.