Struct swc_common::Span
source · [−]pub struct Span {
pub lo: BytePos,
pub hi: BytePos,
pub ctxt: SyntaxContext,
}
Expand description
Spans represent a region of code, used for error reporting. Positions in
spans are absolute positions from the beginning of the source_map
, not
positions relative to SourceFile
s. Methods on the SourceMap
can be used
to relate spans back to the original source.
You must be careful if the span crosses more than one file - you will not be
able to use many of the functions on spans in source_map
and you cannot
assume that the length of the span = hi - lo
; there may be space in the
BytePos
range between files.
Fields
lo: BytePos
hi: BytePos
ctxt: SyntaxContext
Information about where the macro came from, if this piece of code was created by a macro expansion.
Implementations
sourceimpl Span
impl Span
pub fn lo(self) -> BytePos
pub fn new(lo: BytePos, hi: BytePos, ctxt: SyntaxContext) -> Self
pub fn with_lo(&self, lo: BytePos) -> Span
pub fn hi(self) -> BytePos
pub fn with_hi(&self, hi: BytePos) -> Span
pub fn ctxt(self) -> SyntaxContext
pub fn with_ctxt(&self, ctxt: SyntaxContext) -> Span
sourcepub fn is_dummy_ignoring_cmt(self) -> bool
pub fn is_dummy_ignoring_cmt(self) -> bool
Returns true
if this is a dummy span with any hygienic context.
sourcepub fn shrink_to_lo(self) -> Span
pub fn shrink_to_lo(self) -> Span
Returns a new span representing an empty span at the beginning of this span
sourcepub fn shrink_to_hi(self) -> Span
pub fn shrink_to_hi(self) -> Span
Returns a new span representing an empty span at the end of this span
sourcepub fn substitute_dummy(self, other: Span) -> Span
pub fn substitute_dummy(self, other: Span) -> Span
Returns self
if self
is not the dummy span, and other
otherwise.
sourcepub fn source_equal(self, other: Span) -> bool
pub fn source_equal(self, other: Span) -> bool
Return true if the spans are equal with regards to the source text.
Use this instead of ==
when either span could be generated code,
and you only care that they point to the same bytes of source text.
sourcepub fn trim_start(self, other: Span) -> Option<Span>
pub fn trim_start(self, other: Span) -> Option<Span>
Returns Some(span)
, where the start is trimmed by the end of other
sourcepub fn between(self, end: Span) -> Span
pub fn between(self, end: Span) -> Span
Return a Span
between the end of self
to the beginning of end
.
sourcepub fn until(self, end: Span) -> Span
pub fn until(self, end: Span) -> Span
Return a Span
between the beginning of self
to the beginning of
end
.
pub fn from_inner_byte_pos(self, start: usize, end: usize) -> Span
pub fn apply_mark(self, mark: Mark) -> Span
pub fn remove_mark(&mut self) -> Mark
pub fn adjust(&mut self, expansion: Mark) -> Option<Mark>
pub fn glob_adjust(
&mut self,
expansion: Mark,
glob_ctxt: SyntaxContext
) -> Option<Option<Mark>>
pub fn reverse_glob_adjust(
&mut self,
expansion: Mark,
glob_ctxt: SyntaxContext
) -> Option<Option<Mark>>
sourcepub fn has_mark(self, mark: Mark) -> bool
pub fn has_mark(self, mark: Mark) -> bool
Returns true
if self
is marked with mark
.
Panics if mark
is not a valid mark.
sourcepub fn dummy_with_cmt() -> Self
pub fn dummy_with_cmt() -> Self
Dummy span, both position are extremely large numbers so they would be ignore by sourcemap, but can still have comments
Trait Implementations
sourceimpl<'a> Arbitrary<'a> for Span
Available on crate feature arbitrary
only.
impl<'a> Arbitrary<'a> for Span
arbitrary
only.sourcefn arbitrary(u: &mut Unstructured<'_>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self>
Generate an arbitrary value of Self
from the given unstructured data. Read more
sourcefn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Generate an arbitrary value of Self
from the entirety of the given unstructured data. Read more
sourceimpl Archive for Span
impl Archive for Span
type Archived = ArchivedSpan
type Archived = ArchivedSpan
The archived representation of this type. Read more
type Resolver = SpanResolver
type Resolver = SpanResolver
The resolver for this type. It must contain all the additional information from serializing needed to make the archived type from the normal type. Read more
sourceimpl<'de> Deserialize<'de> for Span
impl<'de> Deserialize<'de> for Span
sourcefn 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>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl EqIgnoreSpan for Span
impl EqIgnoreSpan for Span
sourcefn eq_ignore_span(&self, _: &Self) -> bool
fn eq_ignore_span(&self, _: &Self) -> bool
Always returns true
sourceimpl Ord for Span
impl Ord for Span
sourceimpl PartialOrd<Span> for Span
impl PartialOrd<Span> for Span
sourcefn partial_cmp(&self, other: &Span) -> Option<Ordering>
fn partial_cmp(&self, other: &Span) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl Copy for Span
impl Eq for Span
impl StructuralEq for Span
impl StructuralPartialEq for Span
Auto Trait Implementations
impl RefUnwindSafe for Span
impl Send for Span
impl Sync for Span
impl Unpin for Span
impl UnwindSafe for Span
Blanket Implementations
sourceimpl<T> ArchivePointee for T
impl<T> ArchivePointee for T
type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
sourcefn pointer_metadata(
&<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
fn pointer_metadata(
&<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
sourceimpl<T> ArchiveUnsized for T where
T: Archive,
impl<T> ArchiveUnsized for T where
T: Archive,
type Archived = <T as Archive>::Archived
type Archived = <T as Archive>::Archived
The archived counterpart of this type. Unlike Archive
, it may be unsized. Read more
type MetadataResolver = ()
type MetadataResolver = ()
The resolver for the metadata of this type. Read more
sourceunsafe fn resolve_metadata(
&self,
usize,
<T as ArchiveUnsized>::MetadataResolver,
*mut <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata
)
unsafe fn resolve_metadata(
&self,
usize,
<T as ArchiveUnsized>::MetadataResolver,
*mut <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata
)
Creates the archived version of the metadata for this value at the given position and writes it to the given output. Read more
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> CallHasher for T where
T: Hash + ?Sized,
impl<T> CallHasher for T where
T: Hash + ?Sized,
sourceimpl<F, W, T, D> Deserialize<With<T, W>, D> for F where
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
impl<F, W, T, D> Deserialize<With<T, W>, D> for F where
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T, S> SerializeUnsized<S> for T where
T: Serialize<S>,
S: Serializer + ?Sized,
impl<T, S> SerializeUnsized<S> for T where
T: Serialize<S>,
S: Serializer + ?Sized,
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more