Struct CharRange

struct CharRange { ... }

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;

# fn main() {
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

impl CharRange

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

Does this range include a character?

Examples

# use unic_char_range::CharRange;
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'));
fn cmp_char(self: &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.

fn len(self: &Self) -> usize

How many characters are in this range?

fn is_empty(self: &Self) -> bool

Is this range empty?

fn iter(self: &Self) -> CharIter

Create an iterator over this range.

impl CharRange

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

# use unic_char_range::*;
assert_eq!(
    CharRange::closed('a', 'd').iter().collect::<Vec<_>>(),
    vec!['a', 'b', 'c', 'd']
)
fn open_right(start: char, stop: char) -> CharRange

Construct a half open (right) range of characters.

Example

# use unic_char_range::*;
assert_eq!(
    CharRange::open_right('a', 'd').iter().collect::<Vec<_>>(),
    vec!['a', 'b', 'c']
)
fn open_left(start: char, stop: char) -> CharRange

Construct a half open (left) range of characters.

Example

# use unic_char_range::*;
assert_eq!(
    CharRange::open_left('a', 'd').iter().collect::<Vec<_>>(),
    vec!['b', 'c', 'd']
)
fn open(start: char, stop: char) -> CharRange

Construct a fully open range of characters.

Example

# use unic_char_range::*;
assert_eq!(
    CharRange::open('a', 'd').iter().collect::<Vec<_>>(),
    vec!['b', 'c']
)
fn all() -> CharRange

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

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.

impl Clone for CharRange

fn clone(self: &Self) -> CharRange

impl Copy for CharRange

impl Debug for CharRange

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

impl Eq for CharRange

impl Freeze for CharRange

impl From for CharRange

fn from(iter: CharIter) -> CharRange

impl IntoIterator for CharRange

fn into_iter(self: Self) -> CharIter

impl PartialEq for CharRange

fn eq(self: &Self, other: &CharRange) -> bool

impl RefUnwindSafe for CharRange

impl Send for CharRange

impl Sync for CharRange

impl Unpin for CharRange

impl UnsafeUnpin for CharRange

impl UnwindSafe for CharRange

impl<T> Any for CharRange

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for CharRange

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for CharRange

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for CharRange

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> From for CharRange

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into for CharRange

fn into(self: Self) -> U

Calls U::from(self).

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

impl<T, U> TryFrom for CharRange

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for CharRange

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>