Trait SpanRangeExt

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

Provided Methods§

Source

fn get_source_text(self, cx: &impl HasSession) -> 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(self, cx: &impl HasSession) -> 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<T>( self, cx: &impl HasSession, 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_source_text( self, cx: &impl HasSession, 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<T>( self, cx: &impl HasSession, 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( self, cx: &impl HasSession, 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(self, cx: &impl HasSession) -> 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(self, cx: &impl HasSession) -> 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", so this trait is not object safe.

Implementors§