I am trying to download a text file from a given URL using reqwest 0.10.0-alpha.2, which looks like an appropriate tool. I have this in my Cargo.toml file:
[package] name = "..." version = "0.1.0" authors = ["Y*** <y***@***.***>"] edition = "2019" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] reqwest = "0.10.0-alpha.2"
The dependency seems to resolve and I have my Cargo.lock file.
I have this snippet lifted from the docs
let body = reqwest::blocking::get("https://www.rust-lang.org")? .text()?; println!("body = {:?}", body);
But I am getting this error:
| | let body = reqwest::blocking::get("https://www.rust-lang.org")?.text()?; | ^^^^^^^^ could not find `blocking` in `reqwest`
Why? I do see this line on the doc "This requires the optional blocking feature to be enabled" from the above link. It might be just that. However, it is not clear to me how you enable a "feature" for a library in Rust either.
I also tried this (some shooting in the dark):
use reqwest::blocking;
Same error:
| | use reqwest::blocking; | ^^^^^^^^^^^^^^^^^ no `blocking` in the root
Following @edwardw's answer to enable "blocking" in "reqwest", and then also have to change ?
to unwrap
. Not sure, but maybe ?
is from an older version of rust or sth. But it doesn't compile for me.
let body = reqwest::blocking::get("https://www.rust-lang.org") .unwrap() .text(); println!("body = {:?}", body);
It is an optional feature of the crate. You have to explicitly enable it in dependencies:
[dependencies] reqwest = { version = "0.10.0-alpha.2", features = ["blocking"] }
The reqwest::blocking
documentation does mention it:
This requires the optional
blocking
feature to be enabled.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With