Skip to main content

Fold

Trait Fold 

Source
pub trait Fold<From: AstTypes, To: AstTypes = From> {
    type Error;

Show 14 methods // Required methods fn fold_annotation( &mut self, anno: From::Annotation, ) -> Result<To::Annotation, Self::Error>; fn fold_macro_id( &mut self, name: From::MacroId, ) -> Result<To::MacroId, Self::Error>; fn fold_symbol( &mut self, name: From::Symbol, ) -> Result<To::Symbol, Self::Error>; fn fold_path(&mut self, path: From::Path) -> Result<To::Path, Self::Error>; fn fold_literal( &mut self, lit: From::Literal, ) -> Result<To::Literal, Self::Error>; // Provided methods fn fold_at_expr( &mut self, expr: At<Expr<From>, From>, ) -> Result<At<Expr<To>, To>, Self::Error> { ... } fn fold_expr(&mut self, expr: Expr<From>) -> Result<Expr<To>, Self::Error> { ... } fn fold_use(&mut self, item: Use<From>) -> Result<Use<To>, Self::Error> { ... } fn fold_pat(&mut self, pat: Pat<From>) -> Result<Pat<To>, Self::Error> { ... } fn fold_bind(&mut self, bind: Bind<From>) -> Result<Bind<To>, Self::Error> { ... } fn fold_make(&mut self, make: Make<From>) -> Result<Make<To>, Self::Error> { ... } fn fold_makearm( &mut self, arm: MakeArm<From>, ) -> Result<MakeArm<To>, Self::Error> { ... } fn fold_match( &mut self, mtch: Match<From>, ) -> Result<Match<To>, Self::Error> { ... } fn fold_matcharm( &mut self, arm: MatchArm<From>, ) -> Result<MatchArm<To>, Self::Error> { ... }
}
Expand description

Deconstructs an entire AST, and reconstructs it from parts.

Each function acts as a customization point.

Aside from AstTypes, each node in the AST implements the Foldable trait, which provides double dispatch.

Required Associated Types§

Required Methods§

Source

fn fold_annotation( &mut self, anno: From::Annotation, ) -> Result<To::Annotation, Self::Error>

Consumes an Annotation in A, possibly transforms it, and produces a replacement Annotation in B

Source

fn fold_macro_id( &mut self, name: From::MacroId, ) -> Result<To::MacroId, Self::Error>

Consumes a MacroId in A, possibly transforms it, and produces a replacement MacroId in B

Source

fn fold_symbol(&mut self, name: From::Symbol) -> Result<To::Symbol, Self::Error>

Consumes a Symbol in A, possibly transforms it, and produces a replacement Symbol in B

Source

fn fold_path(&mut self, path: From::Path) -> Result<To::Path, Self::Error>

Consumes a Path in A, possibly transforms it, and produces a replacement Path in B

Source

fn fold_literal( &mut self, lit: From::Literal, ) -> Result<To::Literal, Self::Error>

Consumes a Literal in A, possibly transforms it, and produces a replacement Literal in B

Provided Methods§

Source

fn fold_at_expr( &mut self, expr: At<Expr<From>, From>, ) -> Result<At<Expr<To>, To>, Self::Error>

Folds an annotated expression, so the expression and annotation can be seen at once.

Source

fn fold_expr(&mut self, expr: Expr<From>) -> Result<Expr<To>, Self::Error>

Consumes an Expr, possibly transforms it, and produces a replacement Expr

Source

fn fold_use(&mut self, item: Use<From>) -> Result<Use<To>, Self::Error>

Consumes a Use, possibly transforms it, and produces a replacement Use

Source

fn fold_pat(&mut self, pat: Pat<From>) -> Result<Pat<To>, Self::Error>

Consumes a Pat, possibly transforms it, and produces a replacement Pat

Source

fn fold_bind(&mut self, bind: Bind<From>) -> Result<Bind<To>, Self::Error>

Consumes a Bind, possibly transforms it, and produces a replacement Bind

Source

fn fold_make(&mut self, make: Make<From>) -> Result<Make<To>, Self::Error>

Consumes a Make, possibly transforms it, and produces a replacement Make

Source

fn fold_makearm( &mut self, arm: MakeArm<From>, ) -> Result<MakeArm<To>, Self::Error>

Consumes a MakeArm, possibly transforms it, and produces a replacement MakeArm

Source

fn fold_match(&mut self, mtch: Match<From>) -> Result<Match<To>, Self::Error>

Consumes a Make, possibly transforms it, and produces a replacement Make

Source

fn fold_matcharm( &mut self, arm: MatchArm<From>, ) -> Result<MatchArm<To>, Self::Error>

Consumes a MakeArm, possibly transforms it, and produces a replacement MakeArm

Implementors§