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: impl Into<SourceSpan>, spanned: T) -> Self
pub fn new(span: impl Into<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 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 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.
Source§impl<T: Serializable> Span<T>
impl<T: Serializable> Span<T>
pub fn write_into_with_options<W: ByteWriter>( &self, target: &mut W, debug: bool, )
Source§impl<T: Deserializable> Span<T>
impl<T: Deserializable> Span<T>
pub fn read_from_with_options<R: ByteReader>( source: &mut R, debug: bool, ) -> Result<Self, DeserializationError>
Trait Implementations§
Source§impl<T: Deserializable> Deserializable for Span<T>
impl<T: Deserializable> Deserializable for Span<T>
Source§fn read_from<R: ByteReader>(
source: &mut R,
) -> Result<Self, DeserializationError>
fn read_from<R: ByteReader>( source: &mut R, ) -> Result<Self, DeserializationError>
source, attempts to deserialize these bytes
into Self, and returns the result. Read moreSource§fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
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>
Source§impl<T: PrettyPrint> PrettyPrint for Span<T>
impl<T: PrettyPrint> PrettyPrint for Span<T>
Source§fn to_pretty_string(&self) -> String
fn to_pretty_string(&self) -> String
Source§fn pretty_print(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn pretty_print(&self, f: &mut Formatter<'_>) -> Result<(), Error>
Source§impl<T: Serializable> Serializable for Span<T>
impl<T: Serializable> Serializable for Span<T>
Source§fn write_into<W: ByteWriter>(&self, target: &mut W)
fn write_into<W: ByteWriter>(&self, target: &mut W)
self into bytes and writes these bytes into the target.