Struct unic_char_range::CharRange [] [src]

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

The lowest character in this range (inclusive).

The highest character in this range (inclusive).

Methods

impl CharRange
[src]

Constructors

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

[src]

Construct a half open (right) range of characters.

Example

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

[src]

Construct a half open (left) range of characters.

Example

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

[src]

Construct a fully open range of characters.

Example

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

[src]

Construct a range over all characters.

impl CharRange
[src]

Collection-like fn

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

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

[src]

How many characters are in this range?

[src]

Is this range empty?

[src]

Create an iterator over this range.

Trait Implementations

impl From<CharIter> for CharRange
[src]

[src]

Performs the conversion.

impl Copy for CharRange
[src]

impl Clone for CharRange
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for CharRange
[src]

[src]

Formats the value using the given formatter.

impl Eq for CharRange
[src]

impl IntoIterator for CharRange
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

[src]

Creates an iterator from a value. Read more

impl PartialEq<CharRange> for CharRange
[src]

[src]

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

1.0.0
[src]

This method tests for !=.