Generate bindings for indexed struct properties

This allows to export fields of tuple-like structs as indexed JS properties.
This commit is contained in:
Ingvar Stepanyan
2019-04-16 20:31:25 +01:00
parent 10cbc789a8
commit 3a7d384dc8
5 changed files with 47 additions and 35 deletions

View File

@ -227,7 +227,7 @@ pub struct Struct {
#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))]
#[derive(Clone)]
pub struct StructField {
pub name: Ident,
pub name: syn::Member,
pub struct_name: Ident,
pub readonly: bool,
pub ty: syn::Type,

View File

@ -332,7 +332,10 @@ fn shared_struct<'a>(s: &'a ast::Struct, intern: &'a Interner) -> Struct<'a> {
fn shared_struct_field<'a>(s: &'a ast::StructField, intern: &'a Interner) -> StructField<'a> {
StructField {
name: intern.intern(&s.name),
name: match &s.name {
syn::Member::Named(ident) => intern.intern(ident),
syn::Member::Unnamed(index) => intern.intern_str(&index.index.to_string()),
},
readonly: s.readonly,
comments: s.comments.iter().map(|s| &**s).collect(),
}