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<T: TypedSyntaxNode>(node: &T) -> Self
pub fn from_ast<T: TypedSyntaxNode>(node: &T) -> Self
Creates a rewrite node from an AST object.
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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)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