pub trait SpanExt {
    // Required methods
    fn subtract(&self, child_spans: Vec<Span>) -> Vec<Span>;
    fn as_local(&self, outer_span: Span) -> Option<Span>;
    fn overlaps_inclusive(&self, other: Span) -> bool;
    fn trim_end(&self, other: Span) -> Option<Span>;
    fn merge_overlaps(spans: Vec<Span>) -> Vec<Span>;
    fn trim_leading_whitespace(
        &self,
        source_map: &SourceMap
    ) -> Option<Vec<Span>>;
    fn to_string(&self, tcx: TyCtxt<'_>) -> String;
    fn size(&self) -> u32;
}
Expand description

Extension trait for Span.

Required Methods§

source

fn subtract(&self, child_spans: Vec<Span>) -> Vec<Span>

Returns spans for regions in self not in child_spans.

For example:

self:          ---------------
child_spans:    ---      --  ---
output:        -   ------  --
source

fn as_local(&self, outer_span: Span) -> Option<Span>

Returns the version of this span that is local to the current crate, and must be contained in outer_span.

source

fn overlaps_inclusive(&self, other: Span) -> bool

Returns true if self overlaps with other including boundaries.

source

fn trim_end(&self, other: Span) -> Option<Span>

Returns a new span whose end is no later than the start of other, returning None if this would return an empty span.

source

fn merge_overlaps(spans: Vec<Span>) -> Vec<Span>

Merges all overlapping spans in the input vector into single spans.

source

fn trim_leading_whitespace(&self, source_map: &SourceMap) -> Option<Vec<Span>>

Returns a collection of spans inside self that have leading whitespace removed.

Returns None if SourceMap::span_to_snippet fails.

source

fn to_string(&self, tcx: TyCtxt<'_>) -> String

Returns a pretty debug representation of a span.

source

fn size(&self) -> u32

Returns the size (in bytes) of the spanned text.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl SpanExt for Span

source§

fn trim_end(&self, other: Span) -> Option<Span>

source§

fn subtract(&self, child_spans: Vec<Span>) -> Vec<Span>

source§

fn as_local(&self, outer_span: Span) -> Option<Span>

source§

fn overlaps_inclusive(&self, other: Span) -> bool

source§

fn merge_overlaps(spans: Vec<Span>) -> Vec<Span>

source§

fn to_string(&self, tcx: TyCtxt<'_>) -> String

source§

fn size(&self) -> u32

source§

fn trim_leading_whitespace(&self, source_map: &SourceMap) -> Option<Vec<Span>>

Implementors§