LocatedSpan

Struct LocatedSpan 

Source
pub struct LocatedSpan<Span, T = ()> {
    pub extra: T,
    /* private fields */
}
Expand description

Code span together with information related to where it is located in the code.

This type is similar to one from the nom_locate crate, but it has slightly different functionality. In particular, this type provides no method to access other parts of the code (which is performed in nom_locate’s LocatedSpan::get_column() among other methods). As such, this allows to safely replace span info without worrying about undefined behavior.

Fields§

§extra: T

Extra information that can be embedded by the user.

Implementations§

Source§

impl<Span, T> LocatedSpan<Span, T>

Source

pub fn location_offset(&self) -> usize

The offset represents the position of the fragment relatively to the input of the parser. It starts at offset 0.

Source

pub fn location_line(&self) -> u32

The line number of the fragment relatively to the input of the parser. It starts at line 1.

Source

pub fn get_column(&self) -> usize

The column of the fragment start.

Source

pub fn fragment(&self) -> &Span

The fragment that is spanned. The fragment represents a part of the input of the parser.

Source

pub fn map_extra<U>(self, map_fn: impl FnOnce(T) -> U) -> LocatedSpan<Span, U>

Maps the extra field of this span using the provided closure.

Source

pub fn map_fragment<U>( self, map_fn: impl FnOnce(Span) -> U, ) -> LocatedSpan<U, T>

Maps the fragment field of this span using the provided closure.

Source§

impl<Span: Copy, T> LocatedSpan<Span, T>

Source

pub fn as_ref(&self) -> LocatedSpan<Span, &T>

Returns a copy of this span with borrowed extra field.

Source

pub fn copy_with_extra<U>(&self, value: U) -> LocatedSpan<Span, U>

Copies this span with the provided extra field.

Source

pub fn with_no_extra(&self) -> LocatedSpan<Span>

Removes extra field from this span.

Source§

impl<'a> LocatedSpan<&'a str>

Source

pub fn from_str<R>(code: &'a str, range: R) -> Self
where InputSpan<'a>: Input, R: RangeBounds<usize>,

Creates a span from a range in the provided code. This is mostly useful for testing.

Source§

impl LocatedSpan<usize>

Source

pub fn from_str<'a, R>(code: &'a str, range: R) -> Self
where InputSpan<'a>: Input, R: RangeBounds<usize>,

Creates a location from a range in the provided code. This is mostly useful for testing.

Source§

impl<T> LocatedSpan<usize, T>

Source

pub fn to_string(&self, default_name: &str) -> String

Returns a string representation of this location in the form {default_name} at {line}:{column}.

Source

pub fn span<'a>(&self, code: &'a str) -> &'a str

Returns this location in the provided code. It is caller’s responsibility to ensure that this is called with the original code that produced this location.

Trait Implementations§

Source§

impl<Span: Clone, T: Clone> Clone for LocatedSpan<Span, T>

Source§

fn clone(&self) -> LocatedSpan<Span, T>

Returns a duplicate 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<Span: Debug, T: Debug> Debug for LocatedSpan<Span, T>

Source§

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

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

impl<'a, T> From<LocatedSpan<&'a str, T>> for LocatedSpan<&'a str, T>

Source§

fn from(value: LocatedSpan<&'a str, T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<LocatedSpan<&str, T>> for Location<T>

Source§

fn from(value: Spanned<'_, T>) -> Self

Converts to this type from the input type.
Source§

impl<Span: PartialEq, T> PartialEq for LocatedSpan<Span, T>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<Span: Copy, T: Copy> Copy for LocatedSpan<Span, T>

Auto Trait Implementations§

§

impl<Span, T> Freeze for LocatedSpan<Span, T>
where Span: Freeze, T: Freeze,

§

impl<Span, T> RefUnwindSafe for LocatedSpan<Span, T>
where Span: RefUnwindSafe, T: RefUnwindSafe,

§

impl<Span, T> Send for LocatedSpan<Span, T>
where Span: Send, T: Send,

§

impl<Span, T> Sync for LocatedSpan<Span, T>
where Span: Sync, T: Sync,

§

impl<Span, T> Unpin for LocatedSpan<Span, T>
where Span: Unpin, T: Unpin,

§

impl<Span, T> UnwindSafe for LocatedSpan<Span, T>
where Span: UnwindSafe, T: UnwindSafe,

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 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.