pub struct Range {
pub start: Position,
pub end: Position,
}Expand description
A range in a document represented by start and end positions
Ranges are half-open intervals [start, end) where start is inclusive and end is exclusive. This matches standard text editor conventions.
§Examples
use ass_editor::{Position, Range, EditorDocument};
let doc = EditorDocument::from_content("Hello World").unwrap();
let range = Range::new(Position::new(0), Position::new(5)); // "Hello"
// Basic properties
assert_eq!(range.len(), 5);
assert!(!range.is_empty());
assert!(range.contains(Position::new(2)));
assert!(!range.contains(Position::new(5))); // End is exclusive
// Range operations
let other = Range::new(Position::new(3), Position::new(8)); // "lo Wo"
assert!(range.overlaps(&other));
let union = range.union(&other);
assert_eq!(union.start.offset, 0);
assert_eq!(union.end.offset, 8);Fields§
§start: PositionStart position (inclusive)
end: PositionEnd position (exclusive)
Implementations§
Source§impl Range
impl Range
Sourcepub fn new(start: Position, end: Position) -> Self
pub fn new(start: Position, end: Position) -> Self
Create a new range
Automatically normalizes so start <= end
Sourcepub fn union(&self, other: &Self) -> Self
pub fn union(&self, other: &Self) -> Self
Get the union of two ranges (smallest range containing both)
Sourcepub fn intersection(&self, other: &Self) -> Option<Self>
pub fn intersection(&self, other: &Self) -> Option<Self>
Get the intersection of two ranges if they overlap
Trait Implementations§
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§
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