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: TExtra information that can be embedded by the user.
Implementations§
Source§impl<Span, T> LocatedSpan<Span, T>
impl<Span, T> LocatedSpan<Span, T>
Sourcepub fn location_offset(&self) -> usize
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.
Sourcepub fn location_line(&self) -> u32
pub fn location_line(&self) -> u32
The line number of the fragment relatively to the input of the parser. It starts at line 1.
Sourcepub fn get_column(&self) -> usize
pub fn get_column(&self) -> usize
The column of the fragment start.
Sourcepub fn fragment(&self) -> &Span
pub fn fragment(&self) -> &Span
The fragment that is spanned. The fragment represents a part of the input of the parser.
Sourcepub fn map_extra<U>(self, map_fn: impl FnOnce(T) -> U) -> LocatedSpan<Span, U>
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.
Sourcepub fn map_fragment<U>(
self,
map_fn: impl FnOnce(Span) -> U,
) -> LocatedSpan<U, T>
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>
impl<Span: Copy, T> LocatedSpan<Span, T>
Sourcepub fn as_ref(&self) -> LocatedSpan<Span, &T>
pub fn as_ref(&self) -> LocatedSpan<Span, &T>
Returns a copy of this span with borrowed extra field.
Sourcepub fn copy_with_extra<U>(&self, value: U) -> LocatedSpan<Span, U>
pub fn copy_with_extra<U>(&self, value: U) -> LocatedSpan<Span, U>
Copies this span with the provided extra field.
Sourcepub fn with_no_extra(&self) -> LocatedSpan<Span>
pub fn with_no_extra(&self) -> LocatedSpan<Span>
Removes extra field from this span.
Source§impl<'a> LocatedSpan<&'a str>
impl<'a> LocatedSpan<&'a str>
Source§impl LocatedSpan<usize>
impl LocatedSpan<usize>
Trait Implementations§
Source§impl<Span: Clone, T: Clone> Clone for LocatedSpan<Span, T>
impl<Span: Clone, T: Clone> Clone for LocatedSpan<Span, T>
Source§fn clone(&self) -> LocatedSpan<Span, T>
fn clone(&self) -> LocatedSpan<Span, T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more