pub struct TextRange { /* private fields */ }Expand description
Defines a range in a text.
A range is defined by two TextPositions: base and next.
base is the first character (ie. inclusive) and next is just outside of
the range (ie. exclusive).
This graphic shows how they work:
Range
___________
L o r e m i p s u m
- -
| |
| |
base next(in this example, the range would be “rem ip”)
Note that due to this, the character at next may not actually exist.
Implementations
sourceimpl TextRange
impl TextRange
sourcepub fn new(base: TextPosition, next: TextPosition) -> Self
pub fn new(base: TextPosition, next: TextPosition) -> Self
Create a new text range with base as the first character (inclusive)
and next after the last character (exclusive).
They may point to the same location (in which case the range is empty),
but next may not be smaller than base.
See also the documentation on TextPosition for the roles of base
and next.
sourcepub fn new_empty(pos: TextPosition) -> Self
pub fn new_empty(pos: TextPosition) -> Self
Create a new empty range at pos.
sourcepub fn merge(&mut self, other: TextRange)
pub fn merge(&mut self, other: TextRange)
Merge other into self.
self must be immediately before other. This means there may not be
any characters between self.last() and other.first(), but the latter
must still be after the former.
sourcepub fn begin_next_range(&self) -> Self
pub fn begin_next_range(&self) -> Self
Create a new empty range immediately after self.
sourcepub fn base(&self) -> &TextPosition
pub fn base(&self) -> &TextPosition
Get the base character position
sourcepub fn next(&self) -> &TextPosition
pub fn next(&self) -> &TextPosition
Get the next character position
Trait Implementations
sourceimpl PartialEq<TextRange> for TextRange
impl PartialEq<TextRange> for TextRange
impl Eq for TextRange
impl StructuralEq for TextRange
impl StructuralPartialEq for TextRange
Auto Trait Implementations
impl RefUnwindSafe for TextRange
impl Send for TextRange
impl Sync for TextRange
impl Unpin for TextRange
impl UnwindSafe for TextRange
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more