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 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
.
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<'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>
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
.Source§fn get_size_hint(&self) -> usize
fn get_size_hint(&self) -> usize
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<R> Rng for R
impl<R> Rng for R
Source§fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
StandardUniform
distribution. Read moreSource§fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
Source§fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
Source§fn random_bool(&mut self, p: f64) -> bool
fn random_bool(&mut self, p: f64) -> bool
p
of being true. Read moreSource§fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
numerator/denominator
of being
true. Read moreSource§fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
Source§fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
Source§fn gen<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
fn gen<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
random
to avoid conflict with the new gen
keyword in Rust 2024.Rng::random
.Source§fn gen_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
fn gen_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
random_range
Rng::random_range
.Source§impl<R> TryRngCore for R
impl<R> TryRngCore for R
Source§type Error = Infallible
type Error = Infallible
Source§fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>
fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>
u32
.Source§fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>
fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>
u64
.Source§fn try_fill_bytes(
&mut self,
dst: &mut [u8],
) -> Result<(), <R as TryRngCore>::Error>
fn try_fill_bytes( &mut self, dst: &mut [u8], ) -> Result<(), <R as TryRngCore>::Error>
dest
entirely with random data.Source§fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
UnwrapMut
wrapper.