I would like to propose we have a better way of creating
[u8 ; N] types, as these are very useful when dealing with FFI.
I am trying to create a high-level wrapper around the
python27-sys crate. This high-level library should make dealing with pythons reference counts automatic and help with common use-cases.
One of these use-cases is the defining of the module itself. To do this in C you would create a static structure as seen here: python reference.
I have tried find a few different ways of doing this in rust, all of which falls into one of these two categories:
- Create the structure on the heap at runtime instead of on in the
.rodatasection. This could be done e.g. using
lazy_staticor creating the structure directly in the initialization function and then forgetting about it without calling the destructor.
- Do stuff similar to
&[b'f', b'o', b'o', 0] as *const u8 as *const i8.
While the first solution is mostly acceptable for my use-case, it is not so in all cases. The FFI might require a static struct with a specific name or there might be resources (or possibly security) constraints.
You can see my solution to the problem here. It could be improved a bit with macros, but they would not help the issue with writing each letter as a separate entity.
To deal with this I think we should have a less ugly way of declaring static byte arrays.
- We could have
b"foo"be of type
[u8 ; 3]instead of type
- We could re-introduce the
bytes!()macro for this purpose.
Alternatively we could postpone this, as it could probably be solved by either compile-time functions or by procedural macros.
What do you think?