pub struct SourceCode<'src, 'index> { /* private fields */ }
Expand description
Gives access to the source code of a file and allows mapping between TextSize
and SourceLocation
.
Implementations§
source§impl<'src, 'index> SourceCode<'src, 'index>
impl<'src, 'index> SourceCode<'src, 'index>
pub fn new(content: &'src str, index: &'index LineIndex) -> Self
sourcepub fn source_location(&self, offset: TextSize) -> SourceLocation
pub fn source_location(&self, offset: TextSize) -> SourceLocation
Computes the one indexed row and column numbers for offset
.
pub fn line_index(&self, offset: TextSize) -> OneIndexed
sourcepub fn up_to(&self, offset: TextSize) -> &'src str
pub fn up_to(&self, offset: TextSize) -> &'src str
Take the source code up to the given TextSize
.
sourcepub fn after(&self, offset: TextSize) -> &'src str
pub fn after(&self, offset: TextSize) -> &'src str
Take the source code after the given TextSize
.
sourcepub fn slice(&self, range: TextRange) -> &'src str
pub fn slice(&self, range: TextRange) -> &'src str
Take the source code between the given TextRange
.
pub fn line_start(&self, line: OneIndexed) -> TextSize
pub fn line_end(&self, line: OneIndexed) -> TextSize
pub fn line_range(&self, line: OneIndexed) -> TextRange
sourcepub fn line_text(&self, index: OneIndexed) -> &'src str
pub fn line_text(&self, index: OneIndexed) -> &'src str
Returns the source text of the line with the given index
sourcepub fn line_count(&self) -> usize
pub fn line_count(&self) -> usize
Returns the number of lines
Trait Implementations§
source§impl<'src, 'index> Debug for SourceCode<'src, 'index>
impl<'src, 'index> Debug for SourceCode<'src, 'index>
source§impl PartialEq for SourceCode<'_, '_>
impl PartialEq for SourceCode<'_, '_>
impl Eq for SourceCode<'_, '_>
Auto Trait Implementations§
impl<'src, 'index> Freeze for SourceCode<'src, 'index>
impl<'src, 'index> RefUnwindSafe for SourceCode<'src, 'index>
impl<'src, 'index> Send for SourceCode<'src, 'index>
impl<'src, 'index> Sync for SourceCode<'src, 'index>
impl<'src, 'index> Unpin for SourceCode<'src, 'index>
impl<'src, 'index> UnwindSafe for SourceCode<'src, 'index>
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