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
low: char
The lowest character in this range (inclusive).
high: char
The highest character in this range (inclusive).
Methods
impl CharRange[src]
impl CharRangeConstructors
pub fn closed(start: char, stop: char) -> CharRange[src]
pub fn closed(start: char, stop: char) -> CharRangeConstruct 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]
pub fn open_right(start: char, stop: char) -> CharRangeConstruct 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]
pub fn open_left(start: char, stop: char) -> CharRangeConstruct 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]
pub fn open(start: char, stop: char) -> CharRangeConstruct a fully open range of characters.
Example
assert_eq!( CharRange::open('a', 'd').iter().collect::<Vec<_>>(), vec!['b', 'c'] )
pub fn all() -> CharRange[src]
pub fn all() -> CharRangeConstruct a range over all characters.
impl CharRange[src]
impl CharRangeCollection-like fn
pub fn contains(&self, ch: char) -> bool[src]
pub fn contains(&self, ch: char) -> boolDoes 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(&self, ch: char) -> Ordering[src]
pub fn cmp(&self, ch: char) -> OrderingDetermine 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]
pub fn len(&self) -> usizeHow many characters are in this range?
pub fn is_empty(&self) -> bool[src]
pub fn is_empty(&self) -> boolIs this range empty?
ⓘImportant traits for CharIterpub fn iter(&self) -> CharIter[src]
pub fn iter(&self) -> CharIterCreate an iterator over this range.
Trait Implementations
impl From<CharRange> for CharIter[src]
impl From<CharRange> for CharIterimpl From<CharIter> for CharRange[src]
impl From<CharIter> for CharRangeimpl Copy for CharRange[src]
impl Copy for CharRangeimpl Clone for CharRange[src]
impl Clone for CharRangefn clone(&self) -> CharRange[src]
fn clone(&self) -> CharRangeReturns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0[src]
fn clone_from(&mut self, source: &Self)Performs copy-assignment from source. Read more
impl Debug for CharRange[src]
impl Debug for CharRangefn fmt(&self, f: &mut Formatter) -> Result[src]
fn fmt(&self, f: &mut Formatter) -> ResultFormats the value using the given formatter. Read more
impl Eq for CharRange[src]
impl Eq for CharRangeimpl IntoIterator for CharRange[src]
impl IntoIterator for CharRangetype Item = char
The type of the elements being iterated over.
type IntoIter = CharIter
Which kind of iterator are we turning this into?
ⓘImportant traits for CharIterfn into_iter(self) -> CharIter[src]
fn into_iter(self) -> CharIterCreates an iterator from a value. Read more
impl PartialEq<CharRange> for CharRange[src]
impl PartialEq<CharRange> for CharRange