Finite state machines in rust; bendns fork to add types.
Diffstat (limited to 'rust-fsm-dsl/src/variant.rs')
-rw-r--r--rust-fsm-dsl/src/variant.rs27
1 files changed, 16 insertions, 11 deletions
diff --git a/rust-fsm-dsl/src/variant.rs b/rust-fsm-dsl/src/variant.rs
index b4373a8..740da8f 100644
--- a/rust-fsm-dsl/src/variant.rs
+++ b/rust-fsm-dsl/src/variant.rs
@@ -22,24 +22,29 @@ pub fn find_type(of: &Variant, list: &[Variant]) -> Option<Type> {
}
pub fn tokenize(
inputs: &[Variant],
- f: impl FnOnce(Vec<TokenStream>) -> TokenStream,
+ f: impl FnOnce(Vec<TokenStream>, Vec<TokenStream>) -> TokenStream,
) -> TokenStream {
let (Ok(x) | Err(x)) = BTreeSet::from_iter(inputs)
.into_iter()
.map(|x| {
let i = &x.ident;
- x.field.as_ref().map_or(Ok(quote! { #i }), |_| {
- let y = find_type(x, inputs);
- y.ok_or(Error::new_spanned(&x.ident, "type never specified"))
- .map(|y| match y {
- Type::Tuple(TypeTuple { elems, .. }) => quote! { #i(#elems) },
- y => quote! {#i(#y)},
- })
- })
+ x.field
+ .as_ref()
+ .map_or(Ok((quote! { #i }, quote! { #i })), |_| {
+ let y = find_type(x, inputs);
+ y.ok_or(Error::new_spanned(&x.ident, "type never specified"))
+ .map(|y| match y {
+ Type::Tuple(TypeTuple { elems, .. }) => {
+ let x = elems.iter().map(|_| quote! { _ });
+ (quote! { #i(#elems) }, quote! { #i(#(#x),* )})
+ }
+ y => (quote! {#i(#y)}, quote! {#i(_)}),
+ })
+ })
})
- .collect::<Result<_>>()
+ .collect::<Result<(Vec<_>, Vec<_>)>>()
.map_err(Error::into_compile_error)
- .map(f);
+ .map(|(a, b)| f(a, b));
x
}