Struct arithmetic_parser::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>: Slice<R>,

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>: Slice<R>,

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

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<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: Copy,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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,

§

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

§

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

§

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.