Questions tagged [rust-wasm]

121 questions
2
votes
0 answers

How to use Reference Types with wasm-bindgen

First of all, I'm newby in rust and webassembly. I'd like to use Reference Types with wasm-bindgen, following theexample in wasm-bindgen book Support for Reference Types I've tried to build my code with the reference types flag wasm-pack build…
Daní
  • 355
  • 1
  • 17
2
votes
2 answers

Rust wasm attatch input event listener to element

How do I add an input event listener to an HtmlInputElement/HtmlTextAreaElement. I'm using web-sys and read this, but following that, all the elements I use inside the closure (in this case especially the input element) get moved into the closure…
Elias
  • 3,592
  • 2
  • 19
  • 42
2
votes
1 answer

How can I enable --gc-targets in my Cargo.toml?

According to the archival notice in wasm-gc, The wasm-pack (and wasm-bindgen) project will already run [--gc-targets] by default for you, so there's no need to run it again. How do we specify this in Cargo.toml explictly?
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
2
votes
0 answers

how to correctly import js script from wasm rust

How do you let webpack know that a chunk is used inside of rust/wasm so that it doesn't get discarded. My try: webpack config: module.exports: { ... entry: { main: './index.js', worker: './worker.js' }, output: { …
Mattia
  • 179
  • 15
2
votes
1 answer

Rust Wasm Bindgen returns object but gets a number

today while doing some rust wasm vs js speed benchmarking with wasm-bindgen, I ran into a problem. I had made a simple struct as you can see here: I used this struct in a simple function called gimmeDirections as shown here: After compiling this…
Artrix
  • 149
  • 10
2
votes
1 answer

Returning more than one value in a function of near protocol contract

I am trying to return two variables in near protocol smart contract pub fn get_product(&self, product_id: u128) -> (String, bool) { let product = self.product_map.get(&product_id).unwrap(); (product.product_details_hash,…
Amiya Behera
  • 2,210
  • 19
  • 32
2
votes
1 answer

How to handle exceptions in NEAR cross contract calls?

How can I catch and handle an exception in a chain of async call between contracts? Suppose, that my transaction initiate the following calls: contractA.run() -> do changes in contractA -> calls contractB.run() -> do changes in contractB …
Robert Zaremba
  • 8,081
  • 7
  • 47
  • 78
2
votes
2 answers

How to create a JS array of Strings from Rust using web_sys?

I am trying to use a Web API that contains a method which accepts an array of strings from Rust. I am using web_sys to "talk" to the JS API, but I can't find a way to pass in an array of static Strings into it. In Rust, unfortunately, the type of…
Renato
  • 12,940
  • 3
  • 54
  • 85
2
votes
1 answer

Getting query string from Window object in WebAssembly in Rust

Context: I am learning Rust & WebAssembly and as a practice exercise I have a project that paints stuff in HTML Canvas from Rust code. I want to get the query string from the web request and from there the code can decide which drawing function to…
Matthew Nichols
  • 4,866
  • 4
  • 41
  • 48
1
vote
0 answers

In Yew, how is it possible to locate index.html in a static/ directory?

I have something going wrong with my Yew App. I try to locate index.html inside the static/ and, I have this in my Trunk.toml file: [build] target = "./static/index.html" And ultimately, my app compiles with a warning which is "no rust project…
1
vote
1 answer

Calling a WASM function that returns a string from Wasmtime

At a high level I am trying to create a Rust host program that loads a WASM module at runtime using Wasmtime and calls a WASM function that returns a string. I can get this working with numeric types such as usize, but can't work out how to handle…
1
vote
1 answer

How to compile Rust for use with WASM's Shared Memory?

When I run a loop in different Web Workers, the loop shares the counter variable across threads despite that the variable should be thread-local. It should not do this, but I don't know how to fix it. The offending loop is in the run function, as…
DDR
  • 392
  • 1
  • 4
  • 14
1
vote
1 answer

can't make new project with wasm-pack new myProjectName

ewmacfarland@Erics-MacBook-Air wasm-crypto % wasm-pack new crypto Error: expected value at line 1 column 1 Caused by: expected value at line 1 column 1 tried un and reinstalling it every way i could run on M1 chip
1
vote
1 answer

How to publish a library for both browser and Node using wasm-pack?

I'm writing a wasm library that I want to be available in both the browser and Node. Does this mean I need to run both wasm-pack publish -t bundler and wasm-pack publish -t node? Is there a way to publish both builds under the same package instead…
KevinH
  • 586
  • 1
  • 8
  • 12
1
vote
1 answer

Output Array TypeScript type using wasm_bindgen on Rust struct field with type Vec

In the project_wasm.d.ts below, I'm trying to output Array instead of the Array coming from js_sys::Array - but can't figure out the correct wasm_bindgen syntax or getter function. The calling TypeScript/NodeJS code works, but I want…
Kevin Hakanson
  • 41,386
  • 23
  • 126
  • 155
1 2
3
8 9