[][src]Struct passerine::common::span::Span

pub struct Span {
    pub source: Option<Rc<Source>>,
    pub offset: usize,
    pub length: usize,
}

A Span refers to a section of a source, much like a &str, but with a reference to a Source rather than a String. A Span is meant to be paired with other datastructures, to be used during error reporting.

Fields

source: Option<Rc<Source>>offset: usizelength: usize

Implementations

impl Span[src]

pub fn new(source: &Rc<Source>, offset: usize, length: usize) -> Span[src]

Create a new Span from an offset with a length. All Spans have access to the Source from whence they came, So they can't be misinterpreted or miscombined.

pub fn point(source: &Rc<Source>, offset: usize) -> Span[src]

A Span that points at a specific point in the source.

pub fn empty() -> Span[src]

Create a new empty Span. An empty Span has only a source, if combined with another Span, the resulting Span will just be the other.

pub fn is_empty(&self) -> bool[src]

Checks if a Span is empty.

pub fn end(&self) -> usize[src]

pub fn later_than(&self, other: &Span) -> bool[src]

Compares two Spans. returns true if this span starts the latest or is the longest in the case of a tie but false there is a total tie or otherwise

pub fn combine(a: &Span, b: &Span) -> Span[src]

Creates a new Span which spans the space of the previous two.

hello this is cool
^^^^^              | Span a
           ^^      | Span b
^^^^^^^^^^^^^      | combined

pub fn join(spans: Vec<Span>) -> Span[src]

Combines a set of Spans (think fold-left over Span::combine).

pub fn contents(&self) -> String[src]

Returns the contents of a Span. This indexes into the source file, so if the Span is along an invalid byte boundary or is empty, the program will panic.

Trait Implementations

impl Clone for Span[src]

impl Debug for Span[src]

impl Display for Span[src]

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

Given a Span, fmt will print out where the Span occurs in its source. Single-line Spans:

12 | x = blatant { error }
   |     ^^^^^^^^^^^^^^^^^

Multi-line Spans:

12 > x -> {
13 >    y = x + 1
14 >    another { error }
15 > }

impl Eq for Span[src]

impl PartialEq<Span> for Span[src]

impl StructuralEq for Span[src]

impl StructuralPartialEq for Span[src]

Auto Trait Implementations

impl !RefUnwindSafe for Span

impl !Send for Span

impl !Sync for Span

impl Unpin for Span

impl UnwindSafe for Span

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.