Struct TextRange

Source
pub struct TextRange {
    pub start: usize,
    pub end: usize,
}
Expand description

a half-open interval in ℕ, [start, end)

Fields§

§start: usize§end: usize

Implementations§

Source§

impl TextRange

Source

pub fn new(start: usize, end: usize) -> Self

caller should check that start < end

Source

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.

Source

pub fn as_range(&self) -> Range<usize>

Source

pub fn empty(&self) -> bool

Source

pub fn contains(&self, pos: usize) -> bool

Source

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);
Source

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.

Source

pub fn includes(&self, other: Self) -> bool

Source

pub fn intersects(&self, other: Self) -> bool

Source

pub fn intersection(&self, other: impl Into<Self>) -> Option<Self>

Source

pub fn advance(&mut self, offset: usize)

Source

pub fn move_back(&self, offset: usize) -> Self

Trait Implementations§

Source§

impl Clone for TextRange

Source§

fn clone(&self) -> TextRange

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TextRange

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T: Into<usize>> From<(T, T)> for TextRange

Source§

fn from((start, end): (T, T)) -> Self

Converts to this type from the input type.
Source§

impl<T: Into<usize>> From<Range<T>> for TextRange

Source§

fn from(range: Range<T>) -> Self

Converts to this type from the input type.
Source§

impl Ord for TextRange

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for TextRange

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for TextRange

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl RangeBounds<usize> for TextRange

Source§

fn start_bound(&self) -> Bound<&usize>

Start index bound. Read more
Source§

fn end_bound(&self) -> Bound<&usize>

End index bound. Read more
1.35.0 · Source§

fn contains<U>(&self, item: &U) -> bool
where T: PartialOrd<U>, U: PartialOrd<T> + ?Sized,

Returns true if item is contained in the range. Read more
Source§

fn is_empty(&self) -> bool
where T: PartialOrd,

🔬This is a nightly-only experimental API. (range_bounds_is_empty)
Returns true if the range contains no items. One-sided ranges (RangeFrom, etc) always return false. Read more
Source§

impl Copy for TextRange

Source§

impl Eq for TextRange

Source§

impl StructuralPartialEq for TextRange

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.