Struct swc_common::source_map::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 private(self) -> Span
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<'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>,
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
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
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>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more