RangesToUpdate

Struct RangesToUpdate 

Source
pub struct RangesToUpdate<'b> { /* private fields */ }
Expand description

A list of Range<usize>s of byte indices in a Buffer that need to be updated

The recommended way to use this struct is the following:

Implementations§

Source§

impl<'b> RangesToUpdate<'b>

Source

pub fn add_ranges( &self, to_add: impl IntoIterator<Item = impl TextRange>, ) -> bool

Adds ranges to the list of those that need updating

Later on, when duat prints on a range that intersects with these, you can call Handle::full_printed_range or Handle::printed_line_ranges in order to get visible ranges, and then call RangesToUpdate::cutoff, or intersecting, or select_from, in order to get the ranges that need updating, which will include these ones that were added by this method, as well as those relating to the changes that took place in the Buffer.

Returns true if any range was added at all.

Source

pub fn update_on( &self, visible: impl IntoIterator<Item = impl TextRange>, ) -> bool

Declares that the ranges given by the iterator have been updated

The visible iterator here should come from one of the methods on the Handle<Buffer> which returns some list of visible ranges. These include Handle::full_printed_range or Handle::printed_line_ranges. You can, of course, also feed only part of these lists, or some other arbitrary range, in order to declare those updated too.

This function will then assume that you have successfully updated the ranges and will cut these out of the list. This will remove the intersections between the ranges that need to be updated and those of the iterator.

It will not completely remove ranges that partially intersect those of the iterator, only truncating them. If you want that behavior, see update_intersecting

Source

pub fn update_intersecting( &self, visible: impl IntoIterator<Item = impl TextRange>, ) -> bool

Declares that any range intersecting with any of those on the iterator has been updated

The visible iterator here should come from one of the methods on the Handle<Buffer> which returns some list of visible ranges. These include Handle::full_printed_range or Handle::printed_line_ranges. You can, of course, also feed only part of these lists, or some other arbitrary range, in order to declare those updated too.

If you want a method that only removes the intersection with the ranges that need updating, see update_on.

Source

pub fn cutoff( &self, visible: impl IntoIterator<Item = impl TextRange>, ) -> Vec<Range<usize>>

Returns a list of intersections between the ranges that need updating and those from an iterator

The visible iterator here should come from one of the methods on the Handle<Buffer> which returns some list of visible ranges. These include Handle::full_printed_range or Handle::printed_line_ranges. You can, of course, also feed only part of these lists, or some other arbitrary range, in order to declare those updated too.

Note that this returns only the intersecting bits. If you want a list of all ranges that at least partially intersect, see intersecting. If you want to do the opposite, i.e., select all ranges from the iterator that intersect with those from the list, see select_from.

This method is useful if you don’t need update full lines, since it will only care about the ranges that have actually changed, which aren’t full lines most of the time. select_from is more useful for updating full lines, since you can generate a list of printed lines from Handle::printed_line_ranges, and select from those only the ranges that have had changes in them. This pattern is used, for example, by duat-treesitter.

Source

pub fn intersecting( &self, visible: impl IntoIterator<Item = impl TextRange>, ) -> Vec<Range<usize>>

Returns a list of all ranges that intersect with those from an iterator

The visible iterator here should come from one of the methods on the Handle<Buffer> which returns some list of visible ranges. These include Handle::full_printed_range or Handle::printed_line_ranges. You can, of course, also feed only part of these lists, or some other arbitrary range, in order to declare those updated too.

Note that this returns the full ranges, not just the parts that intersect. If you want a list of only the intersections, see cutoff. If you want to select the ranges in the iterator that intersect with those from the list, see select_from.

Source

pub fn select_from( &self, visible: impl IntoIterator<Item = impl TextRange>, ) -> Vec<Range<usize>>

Filters an iterator to a list of ranges that intersect with those that need updating

The visible iterator here should come from one of the methods on the Handle<Buffer> which returns some list of visible ranges. These include Handle::full_printed_range or Handle::printed_line_ranges. You can, of course, also feed only part of these lists, or some other arbitrary range, in order to declare those updated too.

This method is really useful if you want to update on full lines, but only do so if the lines have actually changed. If the lines have had changes, those will be in the RangesToUpdate. This method will check if the range of a line intersects with the ranges that need updating. If that is the case, that line will be kept in the returned Vec.

If you want a method that returns only the ranges that have actually changed, check out cutoff. If you want a method that that returns any range from the list that intersects with those of the iterator, check out intersecting.

Auto Trait Implementations§

§

impl<'b> Freeze for RangesToUpdate<'b>

§

impl<'b> !RefUnwindSafe for RangesToUpdate<'b>

§

impl<'b> Send for RangesToUpdate<'b>

§

impl<'b> Sync for RangesToUpdate<'b>

§

impl<'b> Unpin for RangesToUpdate<'b>

§

impl<'b> !UnwindSafe for RangesToUpdate<'b>

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> 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<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, 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.