Suppose, I have two enums, Foo
and A
, and I need to convert specific patterns of Foo
variants in a Vec<Foo>
into A
replacing that pattern of variants by an FA
enum Foo {
F1(i64, i64, i64),
F2(u64, i64),
F3(i64, u64),
FA(A)
}
enum A {
Bar(u64, i64, u64),
Baz(u64, i64, i64, u64),
}
For instance:
If a Foo::F2(x, y)
is followed by a Foo::F3(z, w)
, combine them into A::Bar(x, y, w)
if y == z
Right now, I have something like a state machine which keeps track of state while parsing.
But I need to do this for a lots of enum variants and that would get repetitive.