pub struct Span {
pub start: usize,
pub end: usize,
pub rev: u64,
}Expand description
A half-open byte range [start, end) into a source text, tagged with the
revision of that text it refers to.
Spans are the currency of this crate: every node in a
ParseTree covers a span of the source, and passes
consume a span and produce child spans.
§Examples
use increparse::Span;
let outer = Span::new(0, 10, 0);
let inner = Span::new(2, 5, 0);
assert_eq!(outer.len(), 10);
assert!(outer.contains(&inner));
assert!(outer.overlaps(&inner));
assert!(!inner.contains(&outer));Fields§
§start: usizeByte offset of the first byte covered by the span.
end: usizeByte offset one past the last byte covered by the span.
rev: u64Revision of the source text this span indexes into.
Implementations§
Source§impl Span
impl Span
Sourcepub fn new(start: usize, end: usize, rev: u64) -> Span
pub fn new(start: usize, end: usize, rev: u64) -> Span
Creates a span over [start, end) of source revision rev.
§Panics
Panics in debug builds if start > end.
Sourcepub fn contains_offset(&self, offset: usize) -> bool
pub fn contains_offset(&self, offset: usize) -> bool
Returns true if self contains the byte offset:
start <= offset < end. Zero-width spans never contain anything.
Trait Implementations§
impl Copy for Span
impl Eq for Span
impl StructuralPartialEq for Span
Auto Trait Implementations§
impl Freeze for Span
impl RefUnwindSafe for Span
impl Send for Span
impl Sync for Span
impl Unpin for Span
impl UnsafeUnpin for Span
impl UnwindSafe for Span
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