wasm-bindgen is a rust crate for facilitating high-level interactions between WebAssembly (Wasm) modules and JavaScript.
Questions tagged [wasm-bindgen]
254 questions
0
votes
1 answer
Testing Async Functions
I am using Wasm-Pack and I need to write a unit test for a asynchronous function that references a JavaScript Library. I tried using the futures::executor::block_on in order to get the asynchronous function to return so I could make an assert.…

Savannah Jackson
- 83
- 2
- 9
0
votes
0 answers
Update page while wasm is running
I've made a compiler in Rust and compiled it into wasm.
I have an output field that shows the compiler output to inform the user of the current progress, which I do by running a js function that I import like this:
#[wasm_bindgen(module =…

Shiedix
- 58
- 5
0
votes
0 answers
How to send values bigger than i8 from JS through wasm-memory to Rust?
Currently I'm trying to send values bigger than i8 from JS through wasm-memory to Rust like so:
Rust:
// CREATE WASM MEMORY FOR RUST AND JS DIRECT USE.
const WASM_MEMORY_BUFFER_SIZE: usize = 2; // 2 SLOTS
static mut WASM_MEMORY_BUFFER: [u8;…

23rfew
- 31
- 8
0
votes
1 answer
Production config Webpack build for a Rust, WebAssembly app to apache2 server
I have a Rust, Web assembly wasm app I need to deploy to an apache server. When upload the build, it doesn't run the software, it just shows a list of the files.
The build files look like this:
build
-0.bootstrap.js
-bootstap.js
…

Shingai Munyuki
- 551
- 1
- 11
- 25
0
votes
1 answer
Coerce anyhow::Error to NjError for node-bindgen
I want to wrap a rust function with node-bindgen to return a promise in JavaScript. The function in question returns an anyhow:Error.
This is my goofy attempt:
#[tokio::main]
#[node_bindgen]
async fn warprometo(offset: u32) -> Result<(), NjError> {
…

Skylar Saveland
- 11,116
- 9
- 75
- 91
0
votes
1 answer
Making a rust wasm bindgen future example from cc::Build
I don't mean to ask too much, but I think I have surpassed the basic requirements using the Rust VS Code formatter. I'm positive futures are needed, and I believe the run_until local pool method can execute the operation. I think a lifetime elide is…

Nick Carducci for Carface Bank
- 531
- 5
- 16
0
votes
1 answer
How can I create a wasm_bindgen Closure which captures a Rc> without moving out of it?
I have state that needs to be mutated multiple times by JavaScript callbacks (it's a game, so input from the user needs to modify the game state). I can't seem to figure out how to do it though. This is the simplest example I can think of that…

Michael Dorst
- 8,210
- 11
- 44
- 71
0
votes
1 answer
Using polars’ query engine in wasm for a file loaded from the web-page
I am trying to implement a simple web app using a web assembly created with wasm-bindgen. I am entirely new to Rust.
The web page would have a file input element to select a CSV file. The web-assembly code would load this CSV and use polars to…

sovo2014
- 487
- 7
- 17
0
votes
1 answer
Wasm-bindgen overhead for a canvas game?
I learned about how can I use the canvas from rust and wasm-bindgen (example like this: https://rustwasm.github.io/wasm-bindgen/examples/2d-canvas.html). It is pretty fast, but I am guessing still there must be an overhead for every canvas call,…

Jung Ervin
- 358
- 1
- 2
- 8
0
votes
0 answers
Return typescript union with wasm_bindgen
Suppose I have the following rust structs:
struct NumberNode {
val: i64
}
struct StringNode {
val: String
}
pub enum Node {
Number(NumberNode),
String(StringNode),
}
I would like to annotate Node with #[wasm_bindgen] so I can…

Elias
- 3,592
- 2
- 19
- 42
0
votes
2 answers
My rust code compiled to wasm is slower than js, what did i do wrong?
This is the original function that i wanted to translate in rust to compile it in wasm in the idea that it will make it faster ( since it's a hot function in my server )
export const generateRandomGuid = function (): string {
let guid: string =…

Qgruber
- 137
- 1
- 11
0
votes
0 answers
ReferenceError: Cannot access 'heap' before initialization
I am trying to use a wasm compiled from rust bundled with webpack. I have this simple js file that I load in my index.html head:
example-project/src/index.js:
document.addEventListener('readystatechange', async () => {
if (document.readyState…

Connor Low
- 5,900
- 3
- 31
- 52
0
votes
1 answer
How to idiomatically share data between closures with wasm-bindgen?
In my browser application, two closures access data stored in a Rc>. One closure mutably borrows the data, while the other immutably borrows it. The two closures are invoked independently of one another, and this will occasionally result…
user13150624
0
votes
2 answers
Importing a js function with an object parameter - Rust / wasm_bindgen
I'm trying to use a JS function from within rust with wasm_bindgen, the function has an object parameter similar to functions like fetch:
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen]
fn fetch(resource: &str, config: &JsValue);
}
(just using…

Mendy
- 7,612
- 5
- 28
- 42
0
votes
0 answers
Why js_sys::Atomics operations require value of type i32?
I'm trying to use SharedArrayBuffer in rust. I want to accumulated output from n workers in part of sab. As i found out i'm constrained to int array types, but my data stored as floats. I'm using Atomics::add(&rc2, idx as u32, k) where k is my float…

Anatoly Strashkevich
- 1,834
- 4
- 16
- 32