Struct rustpython_ast::source_code::SourceCode
source · 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