mozilla / cbindgen

A project for generating C bindings from Rust code
Mozilla Public License 2.0
2.43k stars 314 forks source link

Annotation to inline type definitions of a field #1004

Open chyyran opened 1 month ago

chyyran commented 1 month ago

I have the following Rust definition of a struct

#[repr(C)]
pub struct tagged_union_t {
    pub tag: UNION_TYPE,
    pub value: tagged_union_value_t,
}

#[repr(C)]
pub union tagged_union_value_t{
    pub value_1: i32
    pub value_2: i64
}

I'd like an annotation like ///cbindgen:inline-type so the output C header looks like this

typedef struct tagged_union_t {
  UNION_TYPE tag;
  union { int32_t value_1; int64_t value_2; } value;
}