pub trait RuleVisitor {
type PatternVisitor: PatternVisitor;
type ExprVisitor: ExprVisitor;
type Expr;
// Required methods
fn add_arg(
&mut self,
index: usize,
ty: TypeId,
) -> <Self::PatternVisitor as PatternVisitor>::PatternId;
fn add_pattern<F>(&mut self, visitor: F)
where F: FnOnce(&mut Self::PatternVisitor);
fn add_expr<F>(&mut self, visitor: F) -> Self::Expr
where F: FnOnce(&mut Self::ExprVisitor) -> VisitedExpr<Self::ExprVisitor>;
fn expr_as_pattern(
&mut self,
expr: Self::Expr,
) -> <Self::PatternVisitor as PatternVisitor>::PatternId;
fn pattern_as_expr(
&mut self,
pattern: <Self::PatternVisitor as PatternVisitor>::PatternId,
) -> <Self::ExprVisitor as ExprVisitor>::ExprId;
}
Expand description
Visitor interface for Rules. Visitors must be able to visit patterns by implementing PatternVisitor, and to visit expressions by providing a type that implements ExprVisitor.
Required Associated Types§
Sourcetype PatternVisitor: PatternVisitor
type PatternVisitor: PatternVisitor
The type of pattern visitors constructed by RuleVisitor::add_pattern.
Sourcetype ExprVisitor: ExprVisitor
type ExprVisitor: ExprVisitor
The type of expression visitors constructed by RuleVisitor::add_expr.
Sourcetype Expr
type Expr
The type returned from RuleVisitor::add_expr, which may be exchanged for a subpattern identifier using RuleVisitor::expr_as_pattern.
Required Methods§
Sourcefn add_arg(
&mut self,
index: usize,
ty: TypeId,
) -> <Self::PatternVisitor as PatternVisitor>::PatternId
fn add_arg( &mut self, index: usize, ty: TypeId, ) -> <Self::PatternVisitor as PatternVisitor>::PatternId
Visit one of the arguments to the top-level pattern.
Sourcefn add_pattern<F>(&mut self, visitor: F)where
F: FnOnce(&mut Self::PatternVisitor),
fn add_pattern<F>(&mut self, visitor: F)where
F: FnOnce(&mut Self::PatternVisitor),
Visit a pattern, used once for the rule’s left-hand side and once for each if-let. You can
determine which part of the rule the pattern comes from based on whether the PatternId
passed to the first call to this visitor came from add_arg
or expr_as_pattern
.
Sourcefn add_expr<F>(&mut self, visitor: F) -> Self::Expr
fn add_expr<F>(&mut self, visitor: F) -> Self::Expr
Visit an expression, used once for each if-let and once for the rule’s right-hand side.
Sourcefn expr_as_pattern(
&mut self,
expr: Self::Expr,
) -> <Self::PatternVisitor as PatternVisitor>::PatternId
fn expr_as_pattern( &mut self, expr: Self::Expr, ) -> <Self::PatternVisitor as PatternVisitor>::PatternId
Given an expression from RuleVisitor::add_expr, return an identifier that can be used with a pattern visitor in RuleVisitor::add_pattern.
Sourcefn pattern_as_expr(
&mut self,
pattern: <Self::PatternVisitor as PatternVisitor>::PatternId,
) -> <Self::ExprVisitor as ExprVisitor>::ExprId
fn pattern_as_expr( &mut self, pattern: <Self::PatternVisitor as PatternVisitor>::PatternId, ) -> <Self::ExprVisitor as ExprVisitor>::ExprId
Given an identifier from the pattern visitor, return an identifier that can be used with the expression visitor.
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.