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

Constructors

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

Construct a half open (right) range of characters.

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

Construct a half open (left) range of characters.

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

Construct a fully open range of characters.

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

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

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.

Collection-like fns

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

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.

How many characters are in this range?

Is this range empty?

Create an iterator over this range.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

Which kind of iterator are we turning this into?

The type of the elements being iterated over.

Creates an iterator from a value. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.