Struct Span
struct Span(_)
A region of source code, along with macro expansion information.
Implementations
impl Span
fn def_site() -> SpanA span that resolves at the macro definition site.
fn call_site() -> SpanThe span of the invocation of the current procedural macro. Identifiers created with this span will be resolved as if they were written directly at the macro call location (call-site hygiene) and other code at the macro call site will be able to refer to them as well.
fn mixed_site() -> SpanA span that represents
macro_ruleshygiene, and sometimes resolves at the macro definition site (local variables, labels,$crate) and sometimes at the macro call site (everything else). The span location is taken from the call-site.fn parent(self: &Self) -> Option<Span>The
Spanfor the tokens in the previous macro expansion from whichselfwas generated from, if any.fn source(self: &Self) -> SpanThe span for the origin source code that
selfwas generated from. If thisSpanwasn't generated from other macro expansions then the return value is the same as*self.fn byte_range(self: &Self) -> Range<usize>Returns the span's byte position range in the source file.
fn start(self: &Self) -> SpanCreates an empty span pointing to directly before this span.
fn end(self: &Self) -> SpanCreates an empty span pointing to directly after this span.
fn line(self: &Self) -> usizeThe one-indexed line of the source file where the span starts.
To obtain the line of the span's end, use
span.end().line().fn column(self: &Self) -> usizeThe one-indexed column of the source file where the span starts.
To obtain the column of the span's end, use
span.end().column().fn file(self: &Self) -> StringThe path to the source file in which this span occurs, for display purposes.
This might not correspond to a valid file system path. It might be remapped (e.g.
"/src/lib.rs") or an artificial path (e.g."<command line>").fn local_file(self: &Self) -> Option<PathBuf>The path to the source file in which this span occurs on the local file system.
This is the actual path on disk. It is unaffected by path remapping.
This path should not be embedded in the output of the macro; prefer
file()instead.fn join(self: &Self, other: Span) -> Option<Span>Creates a new span encompassing
selfandother.Returns
Noneifselfandotherare from different files.fn resolved_at(self: &Self, other: Span) -> SpanCreates a new span with the same line/column information as
selfbut that resolves symbols as though it were atother.fn located_at(self: &Self, other: Span) -> SpanCreates a new span with the same name resolution behavior as
selfbut with the line/column information ofother.fn eq(self: &Self, other: &Span) -> boolCompares two spans to see if they're equal.
fn source_text(self: &Self) -> Option<String>Returns the source text behind a span. This preserves the original source code, including spaces and comments. It only returns a result if the span corresponds to real source code.
Note: The observable result of a macro should only rely on the tokens and not on this source text. The result of this function is a best effort to be used for diagnostics only.
fn error<T: Into<String>>(self: Self, message: T) -> DiagnosticCreates a new
Diagnosticwith the givenmessageat the spanself.fn warning<T: Into<String>>(self: Self, message: T) -> DiagnosticCreates a new
Diagnosticwith the givenmessageat the spanself.fn note<T: Into<String>>(self: Self, message: T) -> DiagnosticCreates a new
Diagnosticwith the givenmessageat the spanself.fn help<T: Into<String>>(self: Self, message: T) -> DiagnosticCreates a new
Diagnosticwith the givenmessageat the spanself.
impl Clone for Span
fn clone(self: &Self) -> Span
impl Copy for Span
impl Debug for Span
fn fmt(self: &Self, f: &mut fmt::Formatter<'_>) -> fmt::Result
impl Freeze for Span
impl MultiSpan for crate::Span
fn into_spans(self: Self) -> Vec<Span>
impl RefUnwindSafe for Span
impl Send for Span
impl Sync for Span
impl Unpin for Span
impl UnwindSafe for Span
impl<T> Any for Span
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Span
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Span
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for Span
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for Span
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for Span
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T, U> Into for Span
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Span
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Span
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>