pub trait Transform<'ast> {
type Error;
// Required method
fn transform<N: Visitable>(
&mut self,
node_path: &NodePath<'ast>,
target_node: N,
) -> Result<N, Self::Error>;
// Provided method
fn check_postcondition(&self) -> Result<(), Self::Error> { ... }
}
Expand description
Trait for producing a new AST node from an existing one by applying edits.
Required Associated Types§
Required Methods§
Sourcefn transform<N: Visitable>(
&mut self,
node_path: &NodePath<'ast>,
target_node: N,
) -> Result<N, Self::Error>
fn transform<N: Visitable>( &mut self, node_path: &NodePath<'ast>, target_node: N, ) -> Result<N, Self::Error>
Applies edits to an AST node.
target_node
is an owned node to which the edits will be applied. Because AST transformation happens bottom-up,
child nodes of target_node
may have already been edited - which implies that &target_node == original_node
does
not hold true in general.
original_node
is a read-only reference to the node without any edits applied.
node_path
is a slice containing references to all of the ancestors of original_node
. This is useful for
performing contextual transformations (rather than just type-based) such as transforming an Expr
in a
projection differently to an Expr
in a WHERE
clause.
Transformations are applied from the leaf nodes towards to the root node. Therefore any edits to child nodes of
target_node
will have already been applied therefore care must be taken by implementors of this trait to not undo
edits that have already been applied.
Returns Ok(target_node)
when transformation is successful, else Err(Self::Error)
.
An error during transformation will immediatly terminatate the entire transformation process of the AST.
Provided Methods§
fn check_postcondition(&self) -> Result<(), Self::Error>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.