pub struct Span<'a> {
pub file: &'a str,
pub bytes: ByteSpan,
pub expanded_from: Option<&'a Span<'a>>,
pub included_from: Option<&'a Span<'a>>,
}Expand description
A representation of a unique location in a source file
If the file was included from another file (using the `include
directive), Span::included_from will reference the Span
of the include directive
If the Span is part of a `define directive, each expanded
text macro will have the original Span of the (now expanded) macro,
with Span::expanded_from referencing the original token (in the
`define directive) before expansion
Fields§
§file: &'a str§bytes: ByteSpan§expanded_from: Option<&'a Span<'a>>§included_from: Option<&'a Span<'a>>Implementations§
Source§impl<'a> Span<'a>
impl<'a> Span<'a>
Sourcepub fn compare(&self, other: &Self) -> SpanRelation
pub fn compare(&self, other: &Self) -> SpanRelation
Compare two Spans, returning the relationship of the first relative to the second
let span1 = Span {
file: "test",
bytes: (0..2),
expanded_from: None,
included_from: None
};
let span2 = Span {
file: "test",
bytes: (6..8),
expanded_from: None,
included_from: None
};
assert_eq!(span1.compare(&span2), SpanRelation::Earlier)Expanded Spans will be compared starting at their expansion
point, and working backwards through #defines. Included Spans
will be compared starting at their first #include and working
through the include hierarchy to their final token. If a Span
is included with an `include directive AND expanded from
a `define directive, the former is used before the latter.
Sourcepub const fn expansion_depth(&self) -> usize
pub const fn expansion_depth(&self) -> usize
How many preprocessor macros this Span was expanded from
Sourcepub const fn inclusion_depth(&self) -> usize
pub const fn inclusion_depth(&self) -> usize
How many `include macros this Span was included with