[][src]Struct unic_char_range::CharRange

pub struct CharRange {
    pub low: char,
    pub high: char,
}

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

Methods

impl CharRange[src]

Constructors

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

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']
)

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

Construct a half open (right) range of characters.

Example

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

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

Construct a half open (left) range of characters.

Example

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

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

Construct a fully open range of characters.

Example

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

pub fn all() -> CharRange[src]

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

pub fn assigned_normal_planes() -> CharRange[src]

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.

impl CharRange[src]

Collection-like fns

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

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'));

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

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.

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

How many characters are in this range?

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

Is this range empty?

Important traits for CharIter
pub fn iter(&self) -> CharIter[src]

Create an iterator over this range.

Trait Implementations

impl Debug for CharRange[src]

impl PartialEq<CharRange> for CharRange[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests for !=.

impl Eq for CharRange[src]

impl From<CharRange> for CharIter[src]

impl From<CharIter> for CharRange[src]

impl Copy for CharRange[src]

impl IntoIterator for CharRange[src]

type IntoIter = CharIter

Which kind of iterator are we turning this into?

type Item = char

The type of the elements being iterated over.

impl Clone for CharRange[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

Auto Trait Implementations

impl Send for CharRange

impl Sync for CharRange

Blanket Implementations

impl<T> From for 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, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto 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<T, U> Into for T where
    U: From<T>, 
[src]

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

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

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