pub struct Source(/* private fields */);Expand description
A source file.
All line and column indices start at zero, just like byte indices. Only for user-facing display, you should add 1 to them.
Values of this type are cheap to clone and hash.
Implementations§
Source§impl Source
impl Source
Sourcepub fn detached(text: impl Into<String>) -> Self
pub fn detached(text: impl Into<String>) -> Self
Create a source file without a real id and path, usually for testing.
Sourcepub fn root(&self) -> &SyntaxNode
pub fn root(&self) -> &SyntaxNode
The root node of the file’s untyped syntax tree.
Sourcepub fn lines(&self) -> &Lines<String>
pub fn lines(&self) -> &Lines<String>
An acceleration structure for conversion of UTF-8, UTF-16 and line/column indices.
Sourcepub fn replace(&mut self, new: &str) -> Range<usize>
pub fn replace(&mut self, new: &str) -> Range<usize>
Fully replace the source text.
This performs a naive (suffix/prefix-based) diff of the old and new text
to produce the smallest single edit that transforms old into new and
then calls edit with it.
Returns the range in the new source that was ultimately reparsed.
Sourcepub fn edit(&mut self, replace: Range<usize>, with: &str) -> Range<usize>
pub fn edit(&mut self, replace: Range<usize>, with: &str) -> Range<usize>
Edit the source file by replacing the given range.
Returns the range in the new source that was ultimately reparsed.
The method panics if the replace range is out of bounds.
Sourcepub fn find(&self, span: Span) -> Option<LinkedNode<'_>>
pub fn find(&self, span: Span) -> Option<LinkedNode<'_>>
Find the node with the given span.
Returns None if the span does not point into this source file.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Source
impl RefUnwindSafe for Source
impl Send for Source
impl Sync for Source
impl Unpin for Source
impl UnwindSafe for Source
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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>
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