Generating code for enum destructuring

Hi all,

I'm writing a procedural macro for generating code to implement a trait for enums.
Having the syn::Variant type for a NamedField, it's easy to generate code using to_token_stream(), but it includes all the types associated to the fields.

enum Message {
    Move { x: i32, y: i32 }, // this is easily recreated using to_token-stream()
    ChangeColor(i32, i32, i32),

But what if I want to create a destructuring arm like:

   Message::Move { x, y } => { // whatever code I want 

how to make it ? Using to_token_stream(), I get:

   Message::Move { x: i32, y: i32 } => { // whatever code I want 

Any help appreciated !

This is how this is done in serde_derive

@tguichaoua Thanks, it helped me a lot !

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.