Module source

Source
Expand description

Utils for extracting, inspecting or transforming source code

Structs§

SourceFileRange
SourceText
Handle to a range of text in a source file.

Traits§

HasSession
IntoSpan
Conversion of a value into a Span
SpanRange
Conversion of a value into the range portion of a Span.
SpanRangeExt

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 an ExprKind::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 of snippet_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 a char literal if it’s a str literal containing a single character (or a single byte with ascii_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 πŸ”’