pub struct Range {
pub start: Cur,
pub end: Cur,
pub start_active: bool,
}Expand description
A Range is a closed interval [start, end] that includes both the starting cursor and the ending cursor.
This is equivalent to a stdlib range of the form from..=to rather than from..to as you
might expect. This is also different from how GapBuffer slicing works (which uses traditional
half-open ranges) so care needs to be taken when using a Range to select sub-regions of a
Buffer.
A Range where start == end is considered a “null range” and may be collapsed to a single
cursor via the collapse_null_range method on Dot.
§Why do this?
The primary purpose of a Range is to represent the currently selected text within a given Buffer and we need to be able to manipulate both ends of that selection as isolated Cur instances within the text. As such, we really need both the start and end cursor to have the same semantics and behaviour and we also need to be able to pop them off, manipulate them and recombine them to produce new Ranges. While using a half-open interval would make using Ranges for slicing simpler, the trade off is that it makes a lot of the more complicated operations we need to perform (expanding selections, mapping mouse selections etc) significantly harder to reason about as you end up needing to map back and forth between the end of a Range and the Cur that represents the final character in that Range.
Fields§
§start: Cur§end: Cur§start_active: boolImplementations§
Trait Implementations§
Source§impl Ord for Range
impl Ord for Range
Source§impl PartialOrd for Range
impl PartialOrd for Range
impl Copy for Range
impl Eq for Range
impl StructuralPartialEq for Range
Auto Trait Implementations§
impl Freeze for Range
impl RefUnwindSafe for Range
impl Send for Range
impl Sync for Range
impl Unpin for Range
impl UnwindSafe for Range
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.