Variables never read or used, Failed to convert at JsValue wasm bindgen

I'm working on implementing a QUIC, and WebTransport client and server in the browser. I'm simultaneously trying to compile a Node.js Addon-based respository that depends on quiche written in C++ to WASM with WASI support, and a repository that uses quinn-wasm in Rust to WASM GitHub - guest271314/quinn-wasm at direct-sockets.

A fellow developer got the QUIC code started in Rust part. I modified the original code a few minutes ago, mainly to get the Isolated Web App code to compile and run correctly in the browser. I change some Rust code to set the port to 8081 instead of 0, which UDPSocket in the browser throws for; port can't be 0.

After compiling with rustup wasm-pack build --target web --out-dir pkg I got these warnings, the compilation completed anyway

warning: fields `readable` and `writable` are never read
  --> src/direct_sockets.rs:97:5
   |
96 | pub struct DirectSocketUdp {
   |            --------------- fields in this struct
97 |     readable: Mutex<Pin<Box<web_sys::ReadableStream>>>,
   |     ^^^^^^^^
98 |     writable: Mutex<Pin<Box<web_sys::WritableStream>>>,
   |     ^^^^^^^^
   |
   = note: `#[warn(dead_code)]` on by default

warning: method `write_to_socket` is never used
   --> src/direct_sockets.rs:125:14
    |
115 | impl DirectSocketUdp {
    | -------------------- method in this implementation
...
125 |     async fn write_to_socket(&self, message: UdpMessage) -> Result<(), ...
    |              ^^^^^^^^^^^^^^^

warning: `quinn-wasm` (lib) generated 2 warnings
   Compiling quinn-wasm-direct-sockets v0.1.0 (/media/user/1/quinn-wasm/examples/direct-sockets-web)
    Finished `release` profile [optimized + debuginfo] target(s) in 2.50s

Installing the IWA and running the code I'm getting an error in JsValue (wasm bindgen) in the browser

Error: Failed to convert to UDPSocketStreams: JsValue(Object({"localAddress":"0.0.0.0","localPort":8081,"readable":{},"writable":{}}))

I'm trying to figure out if that's the readable and writable that are never used in the Rust code; if the WHATWG ReadableStream and WritableStream are not getting converted to corresponding Rust, and compiled WASM values - and how to fix that part?

No help from the Rustacean crowd?

warning: method `write_to_socket` is never used
   --> src/direct_sockets.rs:125:14
    |
115 | impl DirectSocketUdp {
    | -------------------- method in this implementation
...
125 |     async fn write_to_socket(&self, message: UdpMessage) -> Result<(), ...
    |              ^^^^^^^^^^^^^^^

The compiler is telling you that nothing calls this function. Is that correct? If it's supposed to be called from outside of the Rust code, maybe it needs to be marked pub.

I don't know. I don't write Rust every day. The idea is to compile all of the mechanics of a WebTransport server to WASM, and supply my/your own UDP socket.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.