pub struct Span { /* private fields */ }
Expand description

A span (a range) in the source code.

It can be created with the constructor Span::new, or with Source::full_span.

Implementations§

source§

impl Span

source

pub fn new(start: Location, length: usize) -> Self

Creates a new span given the start location and length.

Panics

Panics if length is too big, i.e. start.position() + length > start.source().len().

source

pub fn from_range(start: Location, end: Location) -> Self

Creates a new span from a range of locations, where end is exlusive.

Panics

Panics if start and end point to different sources, or if start is past beyond end.

source

pub fn from_range_inclusive(start: Location, end: Location) -> Self

Creates a new span from a range of locations, where end is inclusive.

Panics

Panics if start and end point to different sources, or if start is the same or beyond end.

source

pub fn start(&self) -> Location

The start location of this span.

source

pub fn end(&self) -> Location

The end location of this span.

source

pub fn len(&self) -> usize

The length of this span in string segments.

source

pub fn source(&self) -> &Source

The source code object this span refers to.

source

pub fn as_str(&self) -> &str

Gets the string this span includes as a whole.

source

pub fn content(&self) -> SpanContent

Creates a type that, when displayed, shows the span contents, rather than location.

source

pub fn expand_lines(&self) -> Span

Expands this span in order to contain the whole lines the original span contains.

source

pub fn try_slice<R>(&self, range: R) -> Option<Self>where R: RangeBounds<usize>,

Slices this span to the given range. Returns None if the range is invalid.

source

pub fn segments(&self) -> Segments

Creates an iterator over located grapheme cluster segments, namely LocatedSegments.

source

pub fn indexed_segments(&self) -> IndexedSegments

Creates an IndexedSegments iterator, which yields a tuple of position and a LocatedSegment in that position. Note that this is just for convenience with e.g. nom, LocatedSegment already contains its position, and so Segments can be used.

Trait Implementations§

source§

impl AsRef<Span> for Span

source§

fn as_ref(&self) -> &Self

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl AsRef<str> for Span

source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Clone for Span

source§

fn clone(&self) -> Span

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<'this, 'input> Compare<&'input Span> for &'this Span

source§

fn compare(&self, input: &'input Span) -> CompareResult

Compares self to another value for equality
source§

fn compare_no_case(&self, input: &'input Span) -> CompareResult

Compares self to another value for equality independently of the case. Read more
source§

impl<'this, 'input> Compare<&'input Span> for &'this SpanContent

source§

fn compare(&self, input: &'input Span) -> CompareResult

Compares self to another value for equality
source§

fn compare_no_case(&self, input: &'input Span) -> CompareResult

Compares self to another value for equality independently of the case. Read more
source§

impl<'input> Compare<&'input Span> for Span

source§

fn compare(&self, input: &'input Span) -> CompareResult

Compares self to another value for equality
source§

fn compare_no_case(&self, input: &'input Span) -> CompareResult

Compares self to another value for equality independently of the case. Read more
source§

impl<'input> Compare<&'input Span> for SpanContent

source§

fn compare(&self, input: &'input Span) -> CompareResult

Compares self to another value for equality
source§

fn compare_no_case(&self, input: &'input Span) -> CompareResult

Compares self to another value for equality independently of the case. Read more
source§

impl<'this, 'input> Compare<&'input SpanContent> for &'this Span

source§

fn compare(&self, input: &'input SpanContent) -> CompareResult

Compares self to another value for equality
source§

fn compare_no_case(&self, input: &'input SpanContent) -> CompareResult

Compares self to another value for equality independently of the case. Read more
source§

impl<'input> Compare<&'input SpanContent> for Span

source§

fn compare(&self, input: &'input SpanContent) -> CompareResult

Compares self to another value for equality
source§

fn compare_no_case(&self, input: &'input SpanContent) -> CompareResult

Compares self to another value for equality independently of the case. Read more
source§

impl<'slice, 'seg, 'span> Compare<&'span Span> for Tag<'slice, 'seg>

source§

fn compare(&self, input: &'span Span) -> CompareResult

Compares self to another value for equality
source§

fn compare_no_case(&self, input: &'span Span) -> CompareResult

Compares self to another value for equality independently of the case. Read more
source§

impl<'slice, 'seg, 'tag, 'span> Compare<&'tag Tag<'slice, 'seg>> for &'span Span

source§

fn compare(&self, input: &'tag Tag<'slice, 'seg>) -> CompareResult

Compares self to another value for equality
source§

fn compare_no_case(&self, input: &'tag Tag<'slice, 'seg>) -> CompareResult

Compares self to another value for equality independently of the case. Read more
source§

impl<'slice, 'seg, 'tag> Compare<&'tag Tag<'slice, 'seg>> for Span

source§

fn compare(&self, input: &'tag Tag<'slice, 'seg>) -> CompareResult

Compares self to another value for equality
source§

fn compare_no_case(&self, input: &'tag Tag<'slice, 'seg>) -> CompareResult

Compares self to another value for equality independently of the case. Read more
source§

impl<'this> Compare<Span> for &'this Span

source§

fn compare(&self, input: Span) -> CompareResult

Compares self to another value for equality
source§

fn compare_no_case(&self, input: Span) -> CompareResult

Compares self to another value for equality independently of the case. Read more
source§

impl<'this> Compare<Span> for &'this SpanContent

source§

fn compare(&self, input: Span) -> CompareResult

Compares self to another value for equality
source§

fn compare_no_case(&self, input: Span) -> CompareResult

Compares self to another value for equality independently of the case. Read more
source§

impl Compare<Span> for Span

source§

fn compare(&self, input: Span) -> CompareResult

Compares self to another value for equality
source§

fn compare_no_case(&self, input: Span) -> CompareResult

Compares self to another value for equality independently of the case. Read more
source§

impl Compare<Span> for SpanContent

source§

fn compare(&self, input: Span) -> CompareResult

Compares self to another value for equality
source§

fn compare_no_case(&self, input: Span) -> CompareResult

Compares self to another value for equality independently of the case. Read more
source§

impl<'slice, 'seg, 'span> Compare<Span> for Tag<'slice, 'seg>

source§

fn compare(&self, input: Span) -> CompareResult

Compares self to another value for equality
source§

fn compare_no_case(&self, input: Span) -> CompareResult

Compares self to another value for equality independently of the case. Read more
source§

impl<'this> Compare<SpanContent> for &'this Span

source§

fn compare(&self, input: SpanContent) -> CompareResult

Compares self to another value for equality
source§

fn compare_no_case(&self, input: SpanContent) -> CompareResult

Compares self to another value for equality independently of the case. Read more
source§

impl Compare<SpanContent> for Span

source§

fn compare(&self, input: SpanContent) -> CompareResult

Compares self to another value for equality
source§

fn compare_no_case(&self, input: SpanContent) -> CompareResult

Compares self to another value for equality independently of the case. Read more
source§

impl<'slice, 'seg, 'span> Compare<Tag<'slice, 'seg>> for &'span Span

source§

fn compare(&self, input: Tag<'slice, 'seg>) -> CompareResult

Compares self to another value for equality
source§

fn compare_no_case(&self, input: Tag<'slice, 'seg>) -> CompareResult

Compares self to another value for equality independently of the case. Read more
source§

impl<'slice, 'seg> Compare<Tag<'slice, 'seg>> for Span

source§

fn compare(&self, input: Tag<'slice, 'seg>) -> CompareResult

Compares self to another value for equality
source§

fn compare_no_case(&self, input: Tag<'slice, 'seg>) -> CompareResult

Compares self to another value for equality independently of the case. Read more
source§

impl Debug for Span

source§

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

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

impl Display for Span

source§

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

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

impl<'this, 'tok> FindToken<&'tok LocatedSegment> for &'this Span

source§

fn find_token(&self, token: &'tok LocatedSegment) -> bool

Returns true if self contains the token
source§

impl<'tok> FindToken<&'tok LocatedSegment> for Span

source§

fn find_token(&self, token: &'tok LocatedSegment) -> bool

Returns true if self contains the token
source§

impl<'this, 'tok> FindToken<&'tok str> for &'this Span

source§

fn find_token(&self, token: &'tok str) -> bool

Returns true if self contains the token
source§

impl<'tok> FindToken<&'tok str> for Span

source§

fn find_token(&self, token: &'tok str) -> bool

Returns true if self contains the token
source§

impl<'this, 'tok, 'tok_ref> FindToken<&'tok_ref &'tok str> for &'this Span

source§

fn find_token(&self, token: &'tok_ref &'tok str) -> bool

Returns true if self contains the token
source§

impl<'tok, 'tok_ref> FindToken<&'tok_ref &'tok str> for Span

source§

fn find_token(&self, token: &'tok_ref &'tok str) -> bool

Returns true if self contains the token
source§

impl<'this, 'tok> FindToken<LocatedSegment> for &'this Span

source§

fn find_token(&self, token: LocatedSegment) -> bool

Returns true if self contains the token
source§

impl<'tok> FindToken<LocatedSegment> for Span

source§

fn find_token(&self, token: LocatedSegment) -> bool

Returns true if self contains the token
source§

impl Hash for Span

source§

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

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 InputIter for Span

§

type Item = LocatedSegment

The current input type is a sequence of that Item type. Read more
§

type Iter = Enumerate<<Span as InputIter>::IterElem>

An iterator over the input type, producing the item and its position for use with Slice. If we’re iterating over &str, the position corresponds to the byte index of the character
§

type IterElem = Segments

An iterator over the input type, producing the item
source§

fn iter_indices(&self) -> Self::Iter

Returns an iterator over the elements and their byte offsets
source§

fn iter_elements(&self) -> Self::IterElem

Returns an iterator over the elements
source§

fn position<P>(&self, predicate: P) -> Option<usize>where P: Fn(Self::Item) -> bool,

Finds the byte position of the element
source§

fn slice_index(&self, count: usize) -> Result<usize, Needed>

Get the byte offset from the element’s position in the stream
source§

impl<'this> InputLength for &'this Span

source§

fn input_len(&self) -> usize

Calculates the input length, as indicated by its name, and the name of the trait itself
source§

impl InputLength for Span

source§

fn input_len(&self) -> usize

Calculates the input length, as indicated by its name, and the name of the trait itself
source§

impl InputTake for Span

source§

fn take(&self, count: usize) -> Self

Returns a slice of count bytes. panics if count > length
source§

fn take_split(&self, count: usize) -> (Self, Self)

Split the stream at the count byte offset. panics if count > length
source§

impl InputTakeAtPosition for Span

§

type Item = LocatedSegment

The current input type is a sequence of that Item type. Read more
source§

fn split_at_position<P, E>(&self, predicate: P) -> IResult<Self, Self, E>where P: Fn(Self::Item) -> bool, E: ParseError<Self>,

Looks for the first element of the input type for which the condition returns true, and returns the input up to this position. Read more
source§

fn split_at_position1<P, E>( &self, predicate: P, e: ErrorKind ) -> IResult<Self, Self, E>where P: Fn(Self::Item) -> bool, E: ParseError<Self>,

Looks for the first element of the input type for which the condition returns true and returns the input up to this position. Read more
source§

fn split_at_position_complete<P, E>( &self, predicate: P ) -> IResult<Self, Self, E>where P: Fn(Self::Item) -> bool, E: ParseError<Self>,

Looks for the first element of the input type for which the condition returns true, and returns the input up to this position. Read more
source§

fn split_at_position1_complete<P, E>( &self, predicate: P, e: ErrorKind ) -> IResult<Self, Self, E>where P: Fn(Self::Item) -> bool, E: ParseError<Self>,

Looks for the first element of the input type for which the condition returns true and returns the input up to this position. Read more
source§

impl IntoIterator for Span

§

type Item = LocatedSegment

The type of the elements being iterated over.
§

type IntoIter = Segments

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl Offset for Span

source§

fn offset(&self, second: &Self) -> usize

Offset between the first byte of self and the first byte of the argument
source§

impl Ord for Span

source§

fn cmp(&self, other: &Span) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<Span> for Span

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<Span> for Span

source§

fn partial_cmp(&self, other: &Span) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<R> Slice<R> for Spanwhere R: RangeBounds<usize> + Debug + Clone,

source§

fn slice(&self, range: R) -> Self

Slices self according to the range argument
source§

impl Spanned for Span

source§

fn span(&self) -> Span

Returns the span associated with this value.
source§

impl Eq for Span

source§

impl StructuralEq for Span

source§

impl StructuralPartialEq for Span

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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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 Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

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

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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.