Skip to main content

Span

Struct Span 

Source
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: usize

Byte offset of the first byte covered by the span.

§end: usize

Byte offset one past the last byte covered by the span.

§rev: u64

Revision of the source text this span indexes into.

Implementations§

Source§

impl Span

Source

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.

Source

pub fn len(&self) -> usize

Length of the span in bytes.

Source

pub fn is_empty(&self) -> bool

Returns true if the span covers zero bytes.

Source

pub fn contains(&self, other: &Span) -> bool

Returns true if other lies entirely within self.

Source

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.

Source

pub fn overlaps(&self, other: &Span) -> bool

Returns true if the two spans share at least one byte.

Source

pub fn to_range(&self) -> Range<usize> ⓘ

Converts the span to a Range<usize> suitable for slicing source text.

Trait Implementations§

Source§

impl Clone for Span

Source§

fn clone(&self) -> Span

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Span

Source§

impl Debug for Span

Source§

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

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

impl Display for Span

Source§

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

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

impl Eq for Span

Source§

impl Hash for Span

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Span

Source§

fn eq(&self, other: &Span) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

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> 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<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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.