Skip to main content

SpanExt

Trait SpanExt 

Source
pub trait SpanExt: SpanRange {
    // Provided methods
    fn get_text<'sm>(self, sm: impl HasSourceMap<'sm>) -> Option<SourceText> { ... }
    fn get_source_range<'sm>(
        self,
        sm: impl HasSourceMap<'sm>,
    ) -> Option<SourceFileRange> { ... }
    fn with_source_text<'sm, T>(
        self,
        sm: impl HasSourceMap<'sm>,
        f: impl for<'a> FnOnce(&'a str) -> T,
    ) -> Option<T> { ... }
    fn check_text<'sm>(
        self,
        sm: impl HasSourceMap<'sm>,
        pred: impl for<'a> FnOnce(&'a str) -> bool,
    ) -> bool { ... }
    fn with_source_text_and_range<'sm, T>(
        self,
        sm: impl HasSourceMap<'sm>,
        f: impl for<'a> FnOnce(&'a str, Range<usize>) -> T,
    ) -> Option<T> { ... }
    fn map_range<'sm>(
        self,
        sm: impl HasSourceMap<'sm>,
        f: impl for<'a> FnOnce(&'a SourceFile, &'a str, Range<usize>) -> Option<Range<usize>>,
    ) -> Option<Range<BytePos>> { ... }
    fn with_leading_whitespace<'sm>(
        self,
        sm: impl HasSourceMap<'sm>,
    ) -> Range<BytePos> { ... }
    fn trim_start<'sm>(self, sm: impl HasSourceMap<'sm>) -> Range<BytePos> { ... }
}

Provided Methods§

Source

fn get_text<'sm>(self, sm: impl HasSourceMap<'sm>) -> Option<SourceText>

Attempts to get a handle to the source text. Returns None if either the span is malformed, or the source text is not accessible.

Source

fn get_source_range<'sm>( self, sm: impl HasSourceMap<'sm>, ) -> Option<SourceFileRange>

Gets the source file, and range in the file, of the given span. Returns None if the span extends through multiple files, or is malformed.

Source

fn with_source_text<'sm, T>( self, sm: impl HasSourceMap<'sm>, f: impl for<'a> FnOnce(&'a str) -> T, ) -> Option<T>

Calls the given function with the source text referenced and returns the value. Returns None if the source text cannot be retrieved.

Source

fn check_text<'sm>( self, sm: impl HasSourceMap<'sm>, pred: impl for<'a> FnOnce(&'a str) -> bool, ) -> bool

Checks if the referenced source text satisfies the given predicate. Returns false if the source text cannot be retrieved.

Source

fn with_source_text_and_range<'sm, T>( self, sm: impl HasSourceMap<'sm>, f: impl for<'a> FnOnce(&'a str, Range<usize>) -> T, ) -> Option<T>

Calls the given function with the both the text of the source file and the referenced range, and returns the value. Returns None if the source text cannot be retrieved.

Source

fn map_range<'sm>( self, sm: impl HasSourceMap<'sm>, f: impl for<'a> FnOnce(&'a SourceFile, &'a str, Range<usize>) -> Option<Range<usize>>, ) -> Option<Range<BytePos>>

Calls the given function with the both the text of the source file and the referenced range, and creates a new span with the returned range. Returns None if the source text cannot be retrieved, or no result is returned.

The new range must reside within the same source file.

Source

fn with_leading_whitespace<'sm>( self, sm: impl HasSourceMap<'sm>, ) -> Range<BytePos>

Extends the range to include all preceding whitespace characters.

The range will not be expanded if it would cross a line boundary, the line the range would be extended to ends with a line comment and the text after the range contains a non-whitespace character on the same line. e.g.

( // Some comment
foo)

When the range points to foo, suggesting to remove the range after it’s been extended will cause the ) to be placed inside the line comment as ( // Some comment).

Source

fn trim_start<'sm>(self, sm: impl HasSourceMap<'sm>) -> Range<BytePos>

Trims the leading whitespace from the range.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T: SpanRange> SpanExt for T