pub struct Span<T> { /* private fields */ }Expand description
This type is used to wrap any T with a SourceSpan, and is typically used when it is not
convenient to add a SourceSpan to the type - most commonly because we don’t control the type.
Implementations§
Source§impl<T> Span<T>
impl<T> Span<T>
Sourcepub fn new(span: SourceSpan, spanned: T) -> Self
pub fn new(span: SourceSpan, spanned: T) -> Self
Creates a span for spanned with span.
Sourcepub fn unknown(spanned: T) -> Self
pub fn unknown(spanned: T) -> Self
Creates a Span from a value with an unknown/default location.
Sourcepub fn with_span(self, span: SourceSpan) -> Self
pub fn with_span(self, span: SourceSpan) -> Self
Consume this Span and get a new one with span as the underlying source span
Sourcepub const fn span(&self) -> SourceSpan
pub const fn span(&self) -> SourceSpan
Gets the associated SourceSpan for this spanned item.
Sourcepub fn map<U, F>(self, f: F) -> Span<U>where
F: FnMut(T) -> U,
pub fn map<U, F>(self, f: F) -> Span<U>where
F: FnMut(T) -> U,
Applies a transformation to the spanned value while retaining the same SourceSpan.
Sourcepub fn as_deref<U>(&self) -> Span<&U>
pub fn as_deref<U>(&self) -> Span<&U>
Like Option<T>::as_deref, this constructs a Span<U> wrapping the result of
dereferencing the inner value of type T as a value of type U.
Sourcepub fn set_source_key(&mut self, id: SourceKey)
pub fn set_source_key(&mut self, id: SourceKey)
Manually set the source key for the span of this item
See also SourceSpan::set_source_key.
Sourcepub fn shift(&mut self, count: u32)
pub fn shift(&mut self, count: u32)
Shifts the span right by count units
It is up to the caller to ensure that the shifted text range is valid within its document
Sourcepub fn extend(&mut self, count: u32)
pub fn extend(&mut self, count: u32)
Extends the end of the span by count units.
It is up to the caller to ensure that the extended text range is valid within its document
Sourcepub fn into_parts(self) -> (SourceSpan, T)
pub fn into_parts(self) -> (SourceSpan, T)
Consumes this span, returning the component parts, i.e. the SourceSpan and value of type
T.
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Unwraps the spanned value of type T.