pub struct SourceInfo { /* private fields */ }
Expand description
Struct holding the source string and contains helpers to index lines and to query position information from a source string.
Implementations§
Source§impl SourceInfo
impl SourceInfo
Sourcepub fn count_lines(&self) -> usize
pub fn count_lines(&self) -> usize
Counts the number of lines in the source string.
Sourcepub fn line_span(&self, line: usize) -> Option<Range<usize>>
pub fn line_span(&self, line: usize) -> Option<Range<usize>>
Gets the character range for the provided line, excluding any whitespace.
This returns None if line is not in the interval [0, number of lines)
.
Sourcepub fn read_line(&self, line: usize) -> Option<&str>
pub fn read_line(&self, line: usize) -> Option<&str>
Reads a line from source.
This returns None if line is not in the interval [0, number of lines)
.
Sourcepub fn get_pos_pair(&self, index: usize) -> (usize, usize)
pub fn get_pos_pair(&self, index: usize) -> (usize, usize)
Calculates the line and character number for a given character index.
If the index exceeds the length of the string, the line number is given as the last line and the character number is given as the number of characters after the start of the line.
Trait Implementations§
Source§impl Clone for SourceInfo
impl Clone for SourceInfo
Source§fn clone(&self) -> SourceInfo
fn clone(&self) -> SourceInfo
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for SourceInfo
impl Debug for SourceInfo
Source§impl From<&str> for SourceInfo
impl From<&str> for SourceInfo
Source§impl From<String> for SourceInfo
impl From<String> for SourceInfo
Source§impl PartialEq for SourceInfo
impl PartialEq for SourceInfo
impl Eq for SourceInfo
impl StructuralPartialEq for SourceInfo
Auto Trait Implementations§
impl Freeze for SourceInfo
impl RefUnwindSafe for SourceInfo
impl Send for SourceInfo
impl Sync for SourceInfo
impl Unpin for SourceInfo
impl UnwindSafe for SourceInfo
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