mozilla / cbindgen

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

Implement mangling for arrays #1008

Closed 0e4ef622 closed 3 weeks ago

0e4ef622 commented 1 month ago

input.rs:

#[repr(C)]
pub struct MyStruct<T> {
    field: T
}

#[no_mangle]
pub extern "C" fn my_function(x: MyStruct<[u8; 4]>) {}

cbindgen --lang c input.rs:

#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

typedef struct MyStruct__________u8__________4 {
  uint8_t field[4];
} MyStruct__________u8__________4;

void my_function(struct MyStruct__________u8__________4 x);