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§
Source§impl CharRange
impl CharRange
Constructors
Sourcepub fn closed(start: char, stop: char) -> CharRange
pub 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
assert_eq!(
CharRange::closed('a', 'd').iter().collect::<Vec<_>>(),
vec!['a', 'b', 'c', 'd']
)
Sourcepub fn open_right(start: char, stop: char) -> CharRange
pub fn open_right(start: char, stop: char) -> CharRange
Construct a half open (right) range of characters.
§Example
assert_eq!(
CharRange::open_right('a', 'd').iter().collect::<Vec<_>>(),
vec!['a', 'b', 'c']
)
Sourcepub fn open_left(start: char, stop: char) -> CharRange
pub fn open_left(start: char, stop: char) -> CharRange
Construct a half open (left) range of characters.
§Example
assert_eq!(
CharRange::open_left('a', 'd').iter().collect::<Vec<_>>(),
vec!['b', 'c', 'd']
)
Sourcepub fn open(start: char, stop: char) -> CharRange
pub fn open(start: char, stop: char) -> CharRange
Construct a fully open range of characters.
§Example
assert_eq!(
CharRange::open('a', 'd').iter().collect::<Vec<_>>(),
vec!['b', 'c']
)
Sourcepub fn all() -> CharRange
pub fn all() -> CharRange
Construct a range over all Unicode characters (Unicode Scalar Values).
Sourcepub fn assigned_normal_planes() -> CharRange
pub 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.
Source§impl CharRange
impl CharRange
Collection-like fns
Sourcepub fn contains(&self, ch: char) -> bool
pub fn contains(&self, ch: char) -> bool
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'));
Trait Implementations§
Source§impl IntoIterator for CharRange
impl IntoIterator for CharRange
impl Copy for CharRange
impl Eq for CharRange
Auto Trait Implementations§
impl Freeze for CharRange
impl RefUnwindSafe for CharRange
impl Send for CharRange
impl Sync for CharRange
impl Unpin for CharRange
impl UnwindSafe for CharRange
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)