Currently I write:
extern {
fn X25519(out_shared_key: *mut u8/*[32]*/, private_key: *const u8/*[32]*/,
peers_public_value: *const u8/*[32]*/) -> libc::c_int;
}
I would like to write:
extern {
fn X25519(out_shared_key: &mut [u8;32], private_key: &[u8;32],
peers_public_value: &[u8;32]) -> libc::c_int;
}
The C declaration is:
int X25519(uint8_t out_shared_key[32], const uint8_t private_key[32],
const uint8_t peers_public_value[32]);
which is equivalent to:
int X25519(uint8_t *out_shared_key, const uint8_t *private_key,
const uint8_t *peers_public_value);
The second form of the Rust ffi declaration is safer because it makes it clear that the function doesn't accept NULL pointers and it also makes it clear how long the input arrays are expected to be. However, the Rust reference doesn't document how it translates a reference to a slice or array to a C type, so using the second form is undefined behavior. I would like the Rust Reference to be amended to make it clear that it will call translate references to arrays/slices by passing the result of as_ptr/as_mut_ptr to the C function.
Currently I write:
I would like to write:
The C declaration is:
which is equivalent to:
The second form of the Rust ffi declaration is safer because it makes it clear that the function doesn't accept NULL pointers and it also makes it clear how long the input arrays are expected to be. However, the Rust reference doesn't document how it translates a reference to a slice or array to a C type, so using the second form is undefined behavior. I would like the Rust Reference to be amended to make it clear that it will call translate references to arrays/slices by passing the result of
as_ptr/as_mut_ptrto the C function.