Hi All,
I'm very new to Rust, and I'm exploring it as an option to speed up some slow ndarray operations that I currently have on Javascript. I followed a tutorial (https://www.youtube.com/watch?v=WE33Q8GzTkU) and added this Rust function:
#[no_mangle] pub fn add_numbers(x: i32, y: i32) -> i32 { x + y }
and this JS call:
let t = async() => { const response = await fetch("http://localhost:8080/assets/number_adder.wasm"); const buffer = await response.arrayBuffer(); const obj = await WebAssembly.instantiate(buffer); console.log(obj.instance.exports.add_numbers(1, 2)); // "3" }; t();
So far everything works great, passing to integers x,y and getting the integer sum. The problems began when I tried to pass arrays from JS to RUST. I tried all sorts of combinations, but nothing seems to work.
Ideally, I would pass JS multidimensional array to a Rust ndarray, perform calculations and return some float number as an answer. If I could pass a reference to the array and not have to clone it, it would be super!
Can you help me with a basic example?
Thanks!