Commit d175f950 authored by FloorIsJava's avatar FloorIsJava
Browse files

allow unit structs for statemachines

parent 82813659
......@@ -28,15 +28,18 @@ impl parse::Parse for StateMachine {
let states: States = buf.parse()?;
// Add state tracking field
let ty = &states.name;
let mut field: syn::FieldsNamed = parse_quote! {
{ _statemachine_state: #ty }
};
match &mut struct_item.fields {
syn::Fields::Named(v) => {
let ty = &states.name;
let mut fields: syn::FieldsNamed = parse_quote! {
{ _statemachine_state: #ty }
};
v.named.push(fields.named.pop().unwrap().into_value());
v.named.push(field.named.pop().unwrap().into_value());
},
_ => panic!("Internal error: Fields not named")
syn::Fields::Unit => {
struct_item.fields = syn::Fields::Named(field);
},
syn::Fields::Unnamed(_) => panic!("Unnamed fields are not supported in the state machine struct")
}
Ok(StateMachine { struct_item, states })
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment