0

I'm trying to run a Yew app using Trunk that uses reqwest to get contents of a GitHub repo. For that, I need some extra reqwest features, but Trunk throws out this error:

error[E0433]: failed to resolve: could not find `blocking` in `reqwest`                                                                                                                      
  --> src\github_dir_listing.rs:19:29
   |
19 |     let response = reqwest::blocking::get(contents_url)
   |                             ^^^^^^^^ could not find `blocking` in `reqwest`

My Cargo.toml:

[dependencies]
reqwest = { version = "0.11.0", features = ["blocking", "json"] }
yew = { version = "0.20.0", features = ["csr"] }

[features]
default = ["reqwest/blocking", "reqwest/json"]

Trunk command that I tried: trunk serve --features default.

I also tried defining a "blocking" and "json" feature in the Cargo.toml:

[features]
blocking = ["reqwest/blocking"]
json = ["reqwest/json"]

And then running trunk serve --features blocking,json, but to no avail.

I'm new to Rust, but I'm confused, since cargo build doesn't throw any errors.

PS: I'm using the "blocking" feature since Yew components cannot be async.

tigerros
  • 73
  • 1
  • 6
  • You only need to enable the feature in the `[dependencies]` table *or* the `[features]` table, not both. https://doc.rust-lang.org/cargo/reference/features.html#dependency-features Not sure why this isn't working, though. – drewtato Aug 10 '23 at 01:04
  • You can't use `"blocking"` when targeting WASM in the browser. There is no way for it to be done in a blocking way since the only underlying options are to use the browser APIs through JavaScript which are inherently asynchronous. You can use `async` functions by utilizing [wasm-bindgen-futures](https://yew.rs/docs/concepts/basic-web-technologies/wasm-bindgen#wasm-bindgen-futures) (yew has changed a lot since I last used it so I'm not sure the *best* way to go about it now). – kmdreko Aug 10 '23 at 03:31
  • @kmdreko Thanks! I'm using state (as per the Yew [tutorial](https://yew.rs/docs/tutorial#fetching-data-using-external-rest-api), I just missed it), but I'm wondering if there is a way to do it without it, since it seems excessive. I tried using `Arc>` which I update in an async block spawned through `wasm_bindgen_futures`, but the problem is that the async code completes *after* I get the value from the `Arc`. My code goes: `create arc -> spawn async -> get arc`, but prints indicate this: `create arc -> spawn async -> get arc -> async finished`. Any insights? – tigerros Aug 12 '23 at 03:55

0 Answers0