0

我正在尝试使用该reqwest::blocking示例,但遇到错误。

首先,

"the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `std::ops::Try`)

cannot use the `?` operator in a function that returns `()`

help: the trait `std::ops::Try` is not implemented for `()`
note: required by `std::ops::Try::from_error`

使用以下代码时:

use reqwest;

fn main() {
    let body = reqwest::blocking::get("https://www.rust-lang.org")?
    .text()?;

    println!("body = {:?}", body);

}

从代码中删除?s 后:

no method named `text` found for enum `std::result::Result<reqwest::blocking::Response, reqwest::Error>` in the current scope

method not found in `std::result::Result<reqwest::blocking::Response, reqwest::Error>`
use reqwest;

fn main() {
    let body = reqwest::blocking::get("https://www.rust-lang.org")
    .text();

    println!("body = {:?}", body);

}

我在 cargo.toml 中启用了阻塞功能:

[dependencies]
reqwest = {version = "0.11.3", features = ["blocking"]}

我能够找到与我的问题非常相似的问题,但是它现在已关闭并锁定。如果有任何我没有提及的相关细节,请告诉我。

4

0 回答 0