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 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§
sourcefn get_source_text(self, cx: &impl HasSession) -> Option<SourceText>
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.
sourcefn get_source_range(self, cx: &impl HasSession) -> Option<SourceFileRange>
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.
sourcefn with_source_text<T>(
self,
cx: &impl HasSession,
f: impl for<'a> FnOnce(&'a str) -> T,
) -> Option<T>
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.
sourcefn check_source_text(
self,
cx: &impl HasSession,
pred: impl for<'a> FnOnce(&'a str) -> bool,
) -> bool
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.
sourcefn with_source_text_and_range<T>(
self,
cx: &impl HasSession,
f: impl for<'a> FnOnce(&'a str, Range<usize>) -> T,
) -> Option<T>
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.
sourcefn map_range(
self,
cx: &impl HasSession,
f: impl for<'a> FnOnce(&'a str, Range<usize>) -> Option<Range<usize>>,
) -> Option<Range<BytePos>>
fn map_range( self, cx: &impl HasSession, 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.
sourcefn with_leading_whitespace(self, cx: &impl HasSession) -> Range<BytePos>
fn with_leading_whitespace(self, cx: &impl HasSession) -> Range<BytePos>
Extends the range to include all preceding whitespace characters.
sourcefn trim_start(self, cx: &impl HasSession) -> Range<BytePos>
fn trim_start(self, cx: &impl HasSession) -> Range<BytePos>
Trims the leading whitespace from the range.