Skip to main content

RewriteRule

Trait RewriteRule 

Source
pub trait RewriteRule: Send + Sync {
    // Required methods
    fn meta(&self) -> &'static RuleMeta;
    fn apply(
        &self,
        cx: &mut RuleContext<'_>,
        node_id: NodeId,
    ) -> Result<RuleEffect, RuleError>;
}
Expand description

The central trait that all rewrite rules implement.

Implementors provide static metadata via meta() and the actual tree-rewriting logic via apply(). Rules are typically defined as unit structs with a const RuleMeta and registered in the builtin rule list under rewrite/rules/mod.rs.

Required Methods§

Source

fn meta(&self) -> &'static RuleMeta

Returns the static metadata descriptor for this rule.

Source

fn apply( &self, cx: &mut RuleContext<'_>, node_id: NodeId, ) -> Result<RuleEffect, RuleError>

Attempts to transform the node identified by node_id.

Returns RuleEffect::Applied if the AST was modified, or RuleEffect::Skipped if the node did not need transformation.

Trait Implementations§

Source§

impl Debug for dyn RewriteRule + '_

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§