I'm trying to make a Rust dylib and use it from other languages, like C, Python and others. I've successfully called a Rust function taking an i32 argument from Python. Now I'm trying to make a function that takes an array (or a pointer to it, or whatever is necessary to pass a dataset to Rust).
#![crate_type = "dylib"]
#[no_mangle]
pub extern "C" fn rust_multiply(size: i32, arrayPointer: &i32) -> i32 {
*(arrayPointer)
}
This works as expected. But
#![crate_type = "dylib"]
#[no_mangle]
pub extern "C" fn rust_multiply(size: i32, arrayPointer: &i32) -> i32 {
*(arrayPointer + 1) // trying to get next element
}
fails with
error[E0614]: type `i32` cannot be dereferenced
--> src/lib.rs:4:5
|
4 | *(arrayPointer + 1) // trying to get next element
| ^^^^^^^^^^^^^^^^^^^
Doing this:
pub extern fn rust_multiply(size: i32, array: &[i32]) -> i32
and doing something like array[0]
fails with "length = 0" error.