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 at(source_id: SourceId, offset: usize, spanned: T) -> Self
pub fn at(source_id: SourceId, offset: usize, spanned: T) -> Self
Creates a span for spanned representing a single location, offset.
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_id(&mut self, id: SourceId)
pub fn set_source_id(&mut self, id: SourceId)
Manually set the source id for the span of this item
See also SourceSpan::set_source_id.
Sourcepub fn shift(&mut self, count: ByteOffset)
pub fn shift(&mut self, count: ByteOffset)
Shifts the span right by count units
Sourcepub fn extend(&mut self, count: ByteOffset)
pub fn extend(&mut self, count: ByteOffset)
Extends the end of the span by count units.
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.
Trait Implementations§
Source§impl<'de, T: Deserialize<'de>> Deserialize<'de> for Span<T>
impl<'de, T: Deserialize<'de>> Deserialize<'de> for Span<T>
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<T: Ord> Ord for Span<T>
impl<T: Ord> Ord for Span<T>
Source§impl<T: PartialOrd> PartialOrd for Span<T>
impl<T: PartialOrd> PartialOrd for Span<T>
impl<T: Copy> Copy for Span<T>
impl<T: Eq> Eq for Span<T>
Auto Trait Implementations§
impl<T> Freeze for Span<T>where
T: Freeze,
impl<T> RefUnwindSafe for Span<T>where
T: RefUnwindSafe,
impl<T> Send for Span<T>where
T: Send,
impl<T> Sync for Span<T>where
T: Sync,
impl<T> Unpin for Span<T>where
T: Unpin,
impl<T> UnwindSafe for Span<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more