Skip to content

Commit

Permalink
VisitOperator: implement delegate from &mut VisitOperator (#880)
Browse files Browse the repository at this point in the history
This allows generic code to work with both VisitOperators passed by
value and by reference, without client code needing to implement a
wrapping type that would act as a container for the reference.
  • Loading branch information
nagisa authored Jan 18, 2023
1 parent fdf1527 commit a1fdde0
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions crates/wasmparser/src/readers/core/operators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,3 +326,21 @@ pub trait VisitOperator<'a> {

for_each_operator!(define_visit_operator);
}

macro_rules! define_visit_operator_delegate {
($(@$proposal:ident $op:ident $({ $($arg:ident: $argty:ty),* })? => $visit:ident)*) => {
$(
fn $visit(&mut self $($(,$arg: $argty)*)?) -> Self::Output {
V::$visit(*self, $($($arg),*)?)
}
)*
}
}

impl<'a, 'b, V: VisitOperator<'a>> VisitOperator<'a> for &'b mut V {
type Output = V::Output;
fn visit_operator(&mut self, op: &Operator<'a>) -> Self::Output {
V::visit_operator(*self, op)
}
for_each_operator!(define_visit_operator_delegate);
}

0 comments on commit a1fdde0

Please sign in to comment.