pub trait Substitute<SubstExpr> {
type Target;
type Error;
// Required method
fn substitute(
&self,
expr: &SubstExpr,
var: usize,
) -> Result<Self::Target, Self::Error>;
}Expand description
A syntax node which admits a substitution operation.
Required Associated Types§
Sourcetype Target
type Target
The result of substituting an expression for a variable in this term. For
most AST types this will be Self.
Sourcetype Error
type Error
The type of errors which may occur during substitution.
In the simple case where SubstExpr == Target this should usually be set to
std::convert::Infallible.
However, in more complex cases you may want to implement Substitute<E> for other values of E (such as where you have mutually recursive expression types, each which may contain variables).
In such cases substitute must handle the case where the variable index refers to a position in the wrong type of expression.
N.B. currently the derive macro for Substitute will always use SubstError as the error type.
Required Methods§
Sourcefn substitute(
&self,
expr: &SubstExpr,
var: usize,
) -> Result<Self::Target, Self::Error>
fn substitute( &self, expr: &SubstExpr, var: usize, ) -> Result<Self::Target, Self::Error>
Substitute expr into any variables in the expression matching the specified
de Bruijn index.