I'm writing a project with a lot of interop between wasm and JS library from npm called cesium. I am needing to borrow functions back and forth from js. I might even need to re-implement some of these functions inside wasm. I'd like to be able to test my implementation of a function against the reference implementation for example in wasm-bindgen-test
Or for example,
I have my rust type
#[wasm_bindgen]
#[derive(Clone)]
pub struct Cartesian3 {
pub x: f64,
pub y: f64,
pub z: f64,
}
And the reference type
#[wasm_bindgen(module = "cesium")]
extern "C" {
#[wasm_bindgen(js_name = "Cartesian3")]
pub type JSCartesian3;
/// Getter and setter bindings
}
I want to
- use Cartesian3 wherever I can use JSCartesian3
- Return a Cartesian3 whenever a function on the js side is expecting a JSCartesian3
this class in particular is subject to some really math-y matrix transformations, and I might try my hand at re-implementing these to make them faster. However, I'm not the most mathematically inclined and I'd like to check my work against the original JavaScript library if I'm able.
would I be able to rewrite this binding for JSCartesian3
from this:
#[wasm_bindgen(static_method_of=JSCartesian3,js_name="mostOrthogonalAxis")]
pub fn most_orthogonal_axis(cartesian: JSCartesian3, result: JSCartesian3) -> JSCartesian3;
to this?
#[wasm_bindgen(static_method_of=JSCartesian3,js_name="mostOrthogonalAxis")]
pub fn most_orthogonal_axis(cartesian: JSCartesian3, result: JSCartesian3) -> Cartesian3;
or if I were writing a rust struct that "extends" a js interface that's expecting me to return a JSCartesian3 would I be able to return my wasm Cartesian3 instead?