pub enum RewriteNode {
Trimmed {
node: SyntaxNode,
trim_left: bool,
trim_right: bool,
},
Copied(SyntaxNode),
Modified(ModifiedNode),
Mapped {
origin: TextSpan,
node: Box<RewriteNode>,
},
Text(String),
TextAndMapping(String, Vec<CodeMapping>),
}
Expand description
Interface for modifying syntax nodes.
Variants§
Trimmed
A rewrite node that represents a trimmed copy of a syntax node: one with the leading and trailing trivia excluded.
Copied(SyntaxNode)
Modified(ModifiedNode)
Mapped
Text(String)
TextAndMapping(String, Vec<CodeMapping>)
Implementations§
Source§impl RewriteNode
impl RewriteNode
pub fn new_trimmed(syntax_node: SyntaxNode) -> Self
pub fn new_modified(children: Vec<RewriteNode>) -> Self
pub fn text(text: &str) -> Self
pub fn mapped_text( text: impl Into<String>, db: &dyn SyntaxGroup, origin: &impl TypedSyntaxNode, ) -> Self
pub fn empty() -> Self
Sourcepub fn from_ast(node: &impl TypedSyntaxNode) -> Self
pub fn from_ast(node: &impl TypedSyntaxNode) -> Self
Creates a rewrite node from an AST object.
Sourcepub fn from_ast_trimmed(node: &impl TypedSyntaxNode) -> Self
pub fn from_ast_trimmed(node: &impl TypedSyntaxNode) -> Self
Creates a rewrite node from an AST object - with .
Sourcepub fn modify(&mut self, db: &dyn SyntaxGroup) -> &mut ModifiedNode
pub fn modify(&mut self, db: &dyn SyntaxGroup) -> &mut ModifiedNode
Prepares a node for modification.
Sourcepub fn modify_child(
&mut self,
db: &dyn SyntaxGroup,
index: usize,
) -> &mut RewriteNode
pub fn modify_child( &mut self, db: &dyn SyntaxGroup, index: usize, ) -> &mut RewriteNode
Prepares a node for modification and returns a specific child.
Sourcepub fn interpolate_patched(
code: &str,
patches: &UnorderedHashMap<String, RewriteNode>,
) -> RewriteNode
pub fn interpolate_patched( code: &str, patches: &UnorderedHashMap<String, RewriteNode>, ) -> RewriteNode
Creates a new Rewrite node by interpolating a string with patches.
Each substring of the form $<name>$
is replaced with syntax nodes from patches
.
A $$
substring is replaced with $
.
Sourcepub fn interspersed(
children: impl IntoIterator<Item = RewriteNode>,
separator: RewriteNode,
) -> RewriteNode
pub fn interspersed( children: impl IntoIterator<Item = RewriteNode>, separator: RewriteNode, ) -> RewriteNode
Creates a new Rewrite node by inserting a separator
between each two given children.
Sourcepub fn mapped(self, db: &dyn SyntaxGroup, origin: &impl TypedSyntaxNode) -> Self
pub fn mapped(self, db: &dyn SyntaxGroup, origin: &impl TypedSyntaxNode) -> Self
Creates a new rewrite node wrapped in a mapping to the original code.
Trait Implementations§
Source§impl Clone for RewriteNode
impl Clone for RewriteNode
Source§fn clone(&self) -> RewriteNode
fn clone(&self) -> RewriteNode
Returns a copy 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 RewriteNode
impl Debug for RewriteNode
Source§impl Default for RewriteNode
impl Default for RewriteNode
Source§impl From<SyntaxNode> for RewriteNode
impl From<SyntaxNode> for RewriteNode
Source§fn from(node: SyntaxNode) -> Self
fn from(node: SyntaxNode) -> Self
Converts to this type from the input type.
Source§impl PartialEq for RewriteNode
impl PartialEq for RewriteNode
impl Eq for RewriteNode
impl StructuralPartialEq for RewriteNode
Auto Trait Implementations§
impl Freeze for RewriteNode
impl RefUnwindSafe for RewriteNode
impl Send for RewriteNode
impl Sync for RewriteNode
impl Unpin for RewriteNode
impl UnwindSafe for RewriteNode
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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