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, ) -> SourceCode<'src, 'index>
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
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more