Ranges

Struct Ranges 

Source
pub struct Ranges { /* private fields */ }
Expand description

A list of non intersecting exclusive Range<usize>s

The primary purpose of this struct is to serve parsers by telling Duat which ranges need to be updated. This lets Duat minimize as much as possible the amount of work done to update the Text when it changes in a Buffer.

Implementations§

Source§

impl Ranges

Source

pub fn new(range: Range<usize>) -> Self

Return a new instance of Ranges with an initial Range

Source

pub fn empty() -> Self

Returns a new empty Ranges

Source

pub fn set_min_len(&mut self, min: usize)

Sets a minimum length to keep Ranges

Source

pub fn add(&mut self, new: Range<usize>) -> bool

Adds a range to the list of Range<usize>s

This range will be merged in with the others on the list, so it may bridge gaps between ranges or for longer ranges within, without allowing for the existance of intersecting ranges.

This function will return true if the Ranges were changed by this addition.

Source

pub fn extend(&mut self, ranges: impl IntoIterator<Item = Range<usize>>) -> bool

Adds many Ranges to be merged with the existing ones

This function will return true if the Ranges were changed by this addition.

Source

pub fn remove_on( &mut self, within: Range<usize>, ) -> impl Iterator<Item = Range<usize>>

Removes a Range from the list, returning an Iterator over the Ranges that were taken

Source

pub fn remove_intersecting( &mut self, within: Range<usize>, ) -> impl Iterator<Item = Range<usize>>

Removes all Ranges that intersect with the given one, returning an Iterator over them

Source

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

Applies the add function to another Rangess

Source

pub fn shift_by(&mut self, from: usize, shift: i32)

Shifts the Ranges within by a Change

If the diff is negative (i.e. a part of the ranges were removed), then ranges will be removed ahead of from accordingly.

Source

pub fn len(&self) -> usize

Returns the number of Range<usize>s

Source

pub fn is_empty(&self) -> bool

Returns true if there are no Range<usize>s

Source

pub fn iter(&self) -> impl Iterator<Item = Range<usize>>

An Iterator over the Ranges in this list

Source

pub fn iter_over( &self, within: Range<usize>, ) -> impl Iterator<Item = Range<usize>>

The same as Ranges::remove_on, but without removing, just iterating over the relevant ranges

This method will trim the iterated Ranges to the bounds of within. If you want a non trimmed version of this method, check out iter_intersecting.

Source

pub fn iter_intersecting( &self, within: Range<usize>, ) -> impl Iterator<Item = Range<usize>>

Iterates over all Ranges that intersect with within

If you want to automatically trim those ranges to the bounds of within, check out iter_over. If you want to remove the ranges that intersect with the given one, see, Ranges::remove_intersecting

Source

pub fn intersects_with(&self, range: Range<usize>) -> bool

Wether any Range in this Ranges intersects with the given range

Trait Implementations§

Source§

impl Clone for Ranges

Source§

fn clone(&self) -> Ranges

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 Ranges

Source§

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

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

impl Default for Ranges

Source§

fn default() -> Ranges

Returns the “default value” for a type. Read more
Source§

impl IntoIterator for Ranges

Source§

type IntoIter = IntoIter

Which kind of iterator are we turning this into?
Source§

type Item = Range<usize>

The type of the elements being iterated over.
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl Ord for Ranges

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 Ranges

Source§

fn eq(&self, other: &Self) -> 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 Ranges

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 Eq for Ranges

Auto Trait Implementations§

§

impl Freeze for Ranges

§

impl RefUnwindSafe for Ranges

§

impl Send for Ranges

§

impl Sync for Ranges

§

impl Unpin for Ranges

§

impl UnwindSafe for Ranges

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<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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<I> IntoIteratorExt<I> for I
where I: IntoIterator,

Source§

fn into_into_lender(self) -> FromIntoIter<I>

Turn this IntoIterator into a IntoLender without allocation. Read more
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.