How to implement the C flexible array member patte

2019-06-17 07:01发布

问题:

I would like to implement this C code which uses a flexible array member (sometimes called the struct hack) in Rust:

struct test {
  int key;
  int dataSize;
  int data[];
};
struct test* t = malloc(sizeof(struct test) + sizeOfData)

The empty array at the end of structure allows you to allocate your meta fields and data all at once. Unfortunately, I can't figure out how to do such thing in Rust.

标签: struct rust