I have a very large Function written by JS, I want to reuse it in my Rust lib. I have tried to use wasm-bindgen. I find it can write codes like this:
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
extern "C" {
fn alert(s: &str);
}
#[wasm_bindgen]
pub fn greet(name: &str) {
alert(&format!("Hello, {}!", name));
}
But, when I add a test to run greet
, it throws error.
#[test]
fn test_run() {
greet("foo")
}
Error:
running 1 test
thread 'test_run' panicked at 'cannot call wasm-bindgen imported functions on non-wasm targets', examples/import_js/crate/src/lib.rs:3:1
Is there possible to import the JS function and run it only in a Rust environment ?