Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Handle tuple structs in IDL #1190

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion lang/syn/src/idl/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,28 @@ fn parse_ty_defs(ctx: &CrateContext) -> Result<Vec<IdlTypeDefinition>> {
})
})
.collect::<Result<Vec<IdlField>>>(),
syn::Fields::Unnamed(_) => return None,
syn::Fields::Unnamed(fields) => {
let mut i = -1;
fanatid marked this conversation as resolved.
Show resolved Hide resolved
fields
.unnamed
.iter()
.map(|f: &syn::Field| {
let mut tts = proc_macro2::TokenStream::new();
f.ty.to_tokens(&mut tts);
// Handle array sizes that are constants
let mut tts_string = tts.to_string();
if tts_string.starts_with('[') {
tts_string = resolve_variable_array_length(ctx, tts_string);
}
i += 1;

Ok(IdlField {
name: format!("f{}", i), // name fields as f0, f1, f2, ...
ty: tts_string.parse()?,
})
})
.collect::<Result<Vec<IdlField>>>()
}
_ => panic!("Empty structs are allowed."),
};

Expand Down