I have a structure with a byte array in it. This structure actually comes from the FFI bindings produced by bindgen, and its size is defined in C code using a macro, i.e.:
C code:
#define FOO_SIZE 100
struct the_struct
{
char foo[FOO_SIZE];
/* other fields... */
};
Generated FFI bindings:
pub struct the_struct {
pub foo: [::std::os::raw::c_char; 100usize],
// other fields...
}
I want to make sure that the data coming from the Rust API side fits into foo
. I also do not want to hard code FOO_SIZE
in my Rust API, since it is subject to change.
I understand that this can be done by instantiating the struct first, but then again, that would require explicit initialization of foo
, which seems to be impossible without knowing its size. Furthermore, it is an extra step I want to avoid.
Is it possible to somehow get the size of foo
statically without instantiating the structure? If not, what would be the best approach? Changing C code is not an option.