Trait clippy_utils::source::SpanRangeExt

source ·
pub trait SpanRangeExt: SpanRange {
    // Provided methods
    fn get_source_text(self, cx: &impl LintContext) -> Option<SourceFileRange> { ... }
    fn with_source_text<T>(
        self,
        cx: &impl LintContext,
        f: impl for<'a> FnOnce(&'a str) -> T,
    ) -> Option<T> { ... }
    fn check_source_text(
        self,
        cx: &impl LintContext,
        pred: impl for<'a> FnOnce(&'a str) -> bool,
    ) -> bool { ... }
    fn with_source_text_and_range<T>(
        self,
        cx: &impl LintContext,
        f: impl for<'a> FnOnce(&'a str, Range<usize>) -> T,
    ) -> Option<T> { ... }
    fn map_range(
        self,
        cx: &impl LintContext,
        f: impl for<'a> FnOnce(&'a str, Range<usize>) -> Option<Range<usize>>,
    ) -> Option<Range<BytePos>> { ... }
    fn with_leading_whitespace(self, cx: &impl LintContext) -> Range<BytePos> { ... }
    fn trim_start(self, cx: &impl LintContext) -> Range<BytePos> { ... }
    fn write_source_text_to(
        self,
        cx: &impl LintContext,
        dst: &mut impl Write,
    ) -> Result { ... }
    fn source_text_to_string(self, cx: &impl LintContext) -> Option<String> { ... }
}

Provided Methods§

source

fn get_source_text(self, cx: &impl LintContext) -> 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 LintContext, 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 LintContext, 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 LintContext, 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 LintContext, f: impl for<'a> FnOnce(&'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 LintContext) -> Range<BytePos>

Extends the range to include all preceding whitespace characters.

source

fn trim_start(self, cx: &impl LintContext) -> Range<BytePos>

Trims the leading whitespace from the range.

source

fn write_source_text_to( self, cx: &impl LintContext, dst: &mut impl Write, ) -> Result

Writes the referenced source text to the given writer. Will return Err if the source text could not be retrieved.

source

fn source_text_to_string(self, cx: &impl LintContext) -> Option<String>

Extracts the referenced source text as an owned string.

Object Safety§

This trait is not object safe.

Implementors§