pub enum RewriteNode<'db> {
Trimmed {
node: SyntaxNode<'db>,
trim_left: bool,
trim_right: bool,
},
Copied(SyntaxNode<'db>),
Modified(ModifiedNode<'db>),
Mapped {
origin: TextSpan,
node: Box<RewriteNode<'db>>,
},
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<'db>)
Modified(ModifiedNode<'db>)
Mapped
Text(String)
TextAndMapping(String, Vec<CodeMapping>)
Implementations§
Source§impl<'db> RewriteNode<'db>
impl<'db> RewriteNode<'db>
pub fn new_trimmed(syntax_node: SyntaxNode<'db>) -> Self
pub fn new_modified(children: Vec<RewriteNode<'db>>) -> Self
pub fn text(text: &str) -> Self
pub fn mapped_text( text: impl Into<String>, db: &dyn Database, origin: &impl TypedSyntaxNode<'db>, ) -> Self
pub fn empty() -> Self
Sourcepub fn from_ast(node: &impl TypedSyntaxNode<'db>) -> Self
pub fn from_ast(node: &impl TypedSyntaxNode<'db>) -> Self
Creates a rewrite node from an AST object.
Sourcepub fn from_ast_trimmed(node: &impl TypedSyntaxNode<'db>) -> Self
pub fn from_ast_trimmed(node: &impl TypedSyntaxNode<'db>) -> Self
Creates a rewrite node from an AST object with trimming.
Sourcepub fn modify(&mut self, db: &'db dyn Database) -> &mut ModifiedNode<'db>
pub fn modify(&mut self, db: &'db dyn Database) -> &mut ModifiedNode<'db>
Prepares a node for modification.
Sourcepub fn modify_child(
&mut self,
db: &'db dyn Database,
index: usize,
) -> &mut RewriteNode<'db>
pub fn modify_child( &mut self, db: &'db dyn Database, index: usize, ) -> &mut RewriteNode<'db>
Prepares a node for modification and returns a specific child.
Sourcepub fn interpolate_patched(
code: &str,
patches: &UnorderedHashMap<String, RewriteNode<'db>>,
) -> RewriteNode<'db>
pub fn interpolate_patched( code: &str, patches: &UnorderedHashMap<String, RewriteNode<'db>>, ) -> RewriteNode<'db>
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<'db>>,
separator: RewriteNode<'db>,
) -> RewriteNode<'db>
pub fn interspersed( children: impl IntoIterator<Item = RewriteNode<'db>>, separator: RewriteNode<'db>, ) -> RewriteNode<'db>
Creates a new Rewrite node by inserting a separator between each two given children.
Sourcepub fn mapped(
self,
db: &dyn Database,
origin: &impl TypedSyntaxNode<'db>,
) -> Self
pub fn mapped( self, db: &dyn Database, origin: &impl TypedSyntaxNode<'db>, ) -> Self
Creates a new rewrite node wrapped in a mapping to the original code.
Trait Implementations§
Source§impl<'db> Clone for RewriteNode<'db>
impl<'db> Clone for RewriteNode<'db>
Source§fn clone(&self) -> RewriteNode<'db>
fn clone(&self) -> RewriteNode<'db>
Returns a duplicate 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<'db> Debug for RewriteNode<'db>
impl<'db> Debug for RewriteNode<'db>
Source§impl<'db> Default for RewriteNode<'db>
impl<'db> Default for RewriteNode<'db>
Source§impl<'db> From<SyntaxNode<'db>> for RewriteNode<'db>
impl<'db> From<SyntaxNode<'db>> for RewriteNode<'db>
Source§fn from(node: SyntaxNode<'db>) -> Self
fn from(node: SyntaxNode<'db>) -> Self
Converts to this type from the input type.
Source§impl<'db> PartialEq for RewriteNode<'db>
impl<'db> PartialEq for RewriteNode<'db>
impl<'db> Eq for RewriteNode<'db>
impl<'db> StructuralPartialEq for RewriteNode<'db>
Auto Trait Implementations§
impl<'db> Freeze for RewriteNode<'db>
impl<'db> RefUnwindSafe for RewriteNode<'db>
impl<'db> Send for RewriteNode<'db>
impl<'db> Sync for RewriteNode<'db>
impl<'db> Unpin for RewriteNode<'db>
impl<'db> UnwindSafe for RewriteNode<'db>
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<'db, T> DebugDbUpcast<'db, T> for Twhere
T: ?Sized,
impl<'db, T> DebugDbUpcast<'db, T> for Twhere
T: ?Sized,
fn debug_db_upcast(&'db self) -> &'db T
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