mirror of
https://github.com/Sarsoo/csbindgen.git
synced 2024-12-22 22:46:26 +00:00
treat and parse structs without repr attributes as unit structs
This commit is contained in:
parent
7b614935e5
commit
dd6330a573
@ -170,6 +170,15 @@ pub fn collect_struct(ast: &syn::File, result: &mut Vec<RustStruct>) {
|
||||
is_union: true,
|
||||
});
|
||||
} else if let Item::Struct(t) = item {
|
||||
let mut repr = None;
|
||||
for attr in &t.attrs {
|
||||
let last_segment = attr.path.segments.last().unwrap();
|
||||
if last_segment.ident == "repr" {
|
||||
repr = Some(attr.tokens.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(_) = repr {
|
||||
if let syn::Fields::Named(f) = &t.fields {
|
||||
let struct_name = t.ident.to_string();
|
||||
let fields = collect_fields(f);
|
||||
@ -195,6 +204,16 @@ pub fn collect_struct(ast: &syn::File, result: &mut Vec<RustStruct>) {
|
||||
is_union: false,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// non #[repr(?)] struct, treat as Unit struct
|
||||
let struct_name = t.ident.to_string();
|
||||
let fields: Vec<FieldMember> = Vec::new();
|
||||
result.push(RustStruct {
|
||||
struct_name,
|
||||
fields,
|
||||
is_union: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user