pub struct TextRange {
pub start: usize,
pub end: usize,
}Expand description
a half-open interval in ℕ, [start, end)
Fields§
§start: usize§end: usizeImplementations§
Source§impl TextRange
impl TextRange
Sourcepub fn new_valid(start: usize, end: usize) -> Option<Self>
pub fn new_valid(start: usize, end: usize) -> Option<Self>
Creates a new TextRange only if start < end (non-empty interval).
Returns None if start >= end.
pub fn as_range(&self) -> Range<usize>
pub fn empty(&self) -> bool
pub fn contains(&self, pos: usize) -> bool
Sourcepub fn strict_order(&self, other: &Self) -> Option<Ordering>
pub fn strict_order(&self, other: &Self) -> Option<Ordering>
Determines the strict ordering relationship between two ranges.
Returns Some(Ordering::Less) if this range is completely before the other range.
Returns Some(Ordering::Greater) if this range is completely after the other range.
Returns None if the ranges overlap.
§Examples
use std::cmp::Ordering;
use interval_tree::TextRange;
let a = TextRange::new(0, 5);
let b = TextRange::new(6, 10);
assert_eq!(a.strict_order(&b), Some(Ordering::Less));
let c = TextRange::new(7, 8);
assert_eq!(c.strict_order(&b), None);Sourcepub fn split_at(&mut self, position: usize, left: bool) -> Self
pub fn split_at(&mut self, position: usize, left: bool) -> Self
split self, return the split out interval.
if left is true, the left part is split out and returned.
This function does not check whether position is valid.
pub fn includes(&self, other: Self) -> bool
pub fn intersects(&self, other: Self) -> bool
pub fn intersection(&self, other: impl Into<Self>) -> Option<Self>
pub fn advance(&mut self, offset: usize)
pub fn move_back(&self, offset: usize) -> Self
Trait Implementations§
Source§impl Ord for TextRange
impl Ord for TextRange
Source§impl PartialOrd for TextRange
impl PartialOrd for TextRange
impl Copy for TextRange
impl Eq for TextRange
impl StructuralPartialEq for TextRange
Auto Trait Implementations§
impl Freeze for TextRange
impl RefUnwindSafe for TextRange
impl Send for TextRange
impl Sync for TextRange
impl Unpin for TextRange
impl UnwindSafe for TextRange
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
Mutably borrows from an owned value. Read more