Skip to main content

Transform

Trait Transform 

Source
pub trait Transform {
    // Required method
    fn transform<'life0, 'async_trait>(
        &'life0 mut self,
        expr: Expr,
        ctx: TransformContext,
    ) -> Pin<Box<dyn Future<Output = TransformResult> + Send + 'async_trait>>
       where Self: Sized + 'async_trait,
             'life0: 'async_trait;
}
Expand description

A trait for transforming AST expressions.

This trait allows you to recursively transform expressions by visiting all sub-expressions. The transform method is called recursively on all sub-expressions, allowing you to transform the AST in a composable way.

§Example

use filter_expr::{Expr, Transform};
use async_trait::async_trait;

struct MyTransformer;

#[async_trait]
impl Transform for MyTransformer {
    async fn transform(&mut self, expr: Expr) -> Result<Expr, filter_expr::Error> {
        // Transform the expression before recursing
        Ok(match expr {
            Expr::Field(name) if name == "old_name" => {
                Expr::Field("new_name".to_string())
            }
            other => other,
        })
    }
}

Required Methods§

Source

fn transform<'life0, 'async_trait>( &'life0 mut self, expr: Expr, ctx: TransformContext, ) -> Pin<Box<dyn Future<Output = TransformResult> + Send + 'async_trait>>
where Self: Sized + 'async_trait, 'life0: 'async_trait,

Transform an expression.

Implementors§