Struct Span
struct Span { ... }
A region of source code, along with macro expansion information.
Implementations
impl Span
fn call_site() -> SelfThe 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() -> SelfThe span located at the invocation of the procedural macro, but with local variables, labels, and
$crateresolved at the definition site of the macro. This is the same hygiene behavior asmacro_rules.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 unwrap(self: Self) -> proc_macro::SpanConvert
proc_macro2::Spantoproc_macro::Span.This method is available when building with a nightly compiler, or when building with rustc 1.29+ without semver exempt features.
Panics
Panics if called from outside of a procedural macro. Unlike
proc_macro2::Span, theproc_macro::Spantype can only exist within the context of a procedural macro invocation.fn byte_range(self: &Self) -> Range<usize>Returns the span's byte position range in the source file.
This method requires the
"span-locations"feature to be enabled.When executing in a procedural macro context, the returned range is only accurate if compiled with a nightly toolchain. The stable toolchain does not have this information available. When executing outside of a procedural macro, such as main.rs or build.rs, the byte range is always accurate regardless of toolchain.
fn start(self: &Self) -> LineColumnGet the starting line/column in the source file for this span.
This method requires the
"span-locations"feature to be enabled.When executing in a procedural macro context, the returned line/column are only meaningful if compiled with a nightly toolchain. The stable toolchain does not have this information available. When executing outside of a procedural macro, such as main.rs or build.rs, the line/column are always meaningful regardless of toolchain.
fn end(self: &Self) -> LineColumnGet the ending line/column in the source file for this span.
This method requires the
"span-locations"feature to be enabled.When executing in a procedural macro context, the returned line/column are only meaningful if compiled with a nightly toolchain. The stable toolchain does not have this information available. When executing outside of a procedural macro, such as main.rs or build.rs, the line/column are always meaningful regardless of toolchain.
fn join(self: &Self, other: Span) -> Option<Span>Create a new span encompassing
selfandother.Returns
Noneifselfandotherare from different files.Warning: the underlying
proc_macro::Span::joinmethod is nightly-only. When called from within a procedural macro not using a nightly compiler, this method will always returnNone.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.
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 From for crate::Span
fn from(proc_span: proc_macro::Span) -> Self
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>