Expand description
Utils for extracting, inspecting or transforming source code
Structs§
- Source
File Range - Source
Text - Handle to a range of text in a source file.
Traits§
- HasSession
- Into
Span - Conversion of a value into a
Span
- Span
Range - Conversion of a value into the range portion of a
Span
. - Span
Range Ext
Functions§
- expand_
past_ previous_ comma - Expand a span to include a preceding comma
- expr_
block - Like
snippet_block
, but add braces if the expr is not anExprKind::Block
with no label. - first_
char_ πin_ first_ line - first_
line_ of_ span - Returns a new Span that extends the original Span to the first non-whitespace char of the first line.
- get_
source_ πrange - indent_
of - Returns the indentation of the line of a span
- is_
present_ in_ source - line_
span π - Extends the span to the beginning of the spans line, incl. whitespaces.
- map_
range π - position_
before_ rarrow - Returns the position just before rarrow
- reindent_
multiline - Reindent a multiline string with possibility of ignoring the first line.
- reindent_
multiline_ πinner - snippet
- Converts a span to a code snippet if available, otherwise returns the default.
- snippet_
block - Converts a span (from a block) to a code snippet if available, otherwise use default.
- snippet_
block_ with_ applicability - Same as
snippet_block
, but adapts the applicability level by the rules ofsnippet_with_applicability
. - snippet_
block_ with_ context - snippet_
indent - Gets a snippet of the indentation of the line of a span
- snippet_
opt - Converts a span to a code snippet. Returns
None
if not available. - snippet_
with_ applicability - Same as
snippet
, but it adapts the applicability level by following rules: - snippet_
with_ πapplicability_ sess - snippet_
with_ context - Same as
snippet_with_applicability
, but first walks the span up to the given context. - snippet_
with_ πcontext_ sess - str_
literal_ to_ char_ literal - Converts
expr
to achar
literal if itβs astr
literal containing a single character (or a single byte withascii_only
) - trim_
span - Trims the whitespace from the start and the end of the span.
- trim_
start π - walk_
span_ to_ context - Walks the span up to the target context, thereby returning the macro call site if the span is inside a macro expansion, or the original span if it is not.
- with_
leading_ πwhitespace - with_
source_ πtext - with_
source_ πtext_ and_ range