To use a JavaScript function inside a Rust application, you need to use WebAssembly (WASM). Rust has strong support for generating WebAssembly, and you can use it to call JavaScript functions using Web APIs.
Here's an example using the web-sys
and js-sys
crates in Rust:
main.rs284 chars12 lines
In this example, we're calling a JavaScript function named myJsFunction
, and logging the result to the console using the console::log_1
method from the web-sys
crate.
Keep in mind that in order to use WebAssembly in a browser, you'll need to use a bundler like webpack to package your Rust code into a JavaScript file that can be loaded in a browser.
gistlibby LogSnag