pub struct Source<I: AsRef<str> = String> { /* private fields */ }
Expand description
A type representing a single source that may be referred to by Span
s.
In most cases, a source is a single input file.
Implementations§
source§impl<I: AsRef<str>> Source<I>
impl<I: AsRef<str>> Source<I>
sourcepub fn chars(&self) -> impl Iterator<Item = char> + '_
pub fn chars(&self) -> impl Iterator<Item = char> + '_
Return an iterator over the characters in the source.
sourcepub fn lines(&self) -> impl ExactSizeIterator<Item = Line> + '_
pub fn lines(&self) -> impl ExactSizeIterator<Item = Line> + '_
Return an iterator over the Line
s in this source.
sourcepub fn get_offset_line(&self, offset: usize) -> Option<(Line, usize, usize)>
pub fn get_offset_line(&self, offset: usize) -> Option<(Line, usize, usize)>
Get the line that the given offset appears on, and the line/column numbers of the offset.
Note that the line/column numbers are zero-indexed.
sourcepub fn get_line_range<S: Span>(&self, span: &S) -> Range<usize>
pub fn get_line_range<S: Span>(&self, span: &S) -> Range<usize>
Get the range of lines that this span runs across.
The resulting range is guaranteed to contain valid line indices (i.e: those that can be used for
Source::line
).
sourcepub fn get_line_text(&self, line: Line) -> Option<&str>
pub fn get_line_text(&self, line: Line) -> Option<&str>
Get the source text for a line, excluding trailing whitespace.
Trait Implementations§
source§impl<I: AsRef<str>> Cache<()> for Source<I>
impl<I: AsRef<str>> Cache<()> for Source<I>
source§impl<I: PartialEq + AsRef<str>> PartialEq for Source<I>
impl<I: PartialEq + AsRef<str>> PartialEq for Source<I>
impl<I: Eq + AsRef<str>> Eq for Source<I>
impl<I: AsRef<str>> StructuralEq for Source<I>
impl<I: AsRef<str>> StructuralPartialEq for Source<I>
Auto Trait Implementations§
impl<I> RefUnwindSafe for Source<I>where
I: RefUnwindSafe,
impl<I> Send for Source<I>where
I: Send,
impl<I> Sync for Source<I>where
I: Sync,
impl<I> Unpin for Source<I>where
I: Unpin,
impl<I> UnwindSafe for Source<I>where
I: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more