没有为 impl 实现特质 std::ops::Try

2023-12-02

我克隆了https://gitlab.com/pwoolcoc/soup并运行示例文件。一切正常,但是当我使用与示例文件相同的文件创建新项目时,遇到错误。 代码是:

use std::collections::HashSet;
use std::fmt::Error;
use soup::Soup;
use reqwest;
fn main() -> Result<(), Box<Error>> {
    let resp = reqwest::get("https://docs.rs/soup/0.1.0/soup/")?;
    let soup = Soup::from_reader(resp)?;
    let result = soup
        .tag("section")
        .attr("id", "main")
        .find()
        .and_then(|section| {
            section
                .tag("span")
                .attr("class", "in-band")
                .find()
                .map(|span| span.text())
        });
    assert_eq!(result, Some("Crate soup".to_string()));
    Ok(())
}

货物档案

[package]
name = "testquestion"
version = "0.1.0"
authors = ["wangyiran"]
edition = "2018"

[dependencies]
soup = "0.3"
reqwest =  { version = "0.10.0-alpha.2", features = ["blocking"] }

错误:

error[E0277]: the `?` operator can only be applied to values that implement `std::ops::Try`
   --> src\main.rs:6:16
   | 6 |     let resp = reqwest::get("https://docs.rs/soup/0.1.0/soup/")?;
   |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `?` operator cannot be applied to type `impl std::future::Future`
   |   = help: the trait `std::ops::Try` is not implemented for `impl std::future::Future`
       = note: required by `std::ops::Try::into_result`

error[E0277]: `?` couldn't convert the error to `std::boxed::Box<std::fmt::Error>`
   --> src\main.rs:7:39
   | 7 |    let soup = Soup::from_reader(resp)?;
   |                                          ^ the trait `std::convert::From<std::io::Error>` is not implemented for `std::boxed::Box<std::fmt::Error>`
   |   = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
       = help: the following implementations were found:
            <std::boxed::Box<(dyn std::error::Error + 'a)> as std::convert::From<E>>
            <std::boxed::Box<(dyn std::error::Error + 'static)> as std::convert::From<&str>>
            <std::boxed::Box<(dyn std::error::Error + 'static)> as std::convert::From<std::borrow::Cow<'a, str>>>
            <std::boxed::Box<(dyn std::error::Error + 'static)> as std::convert::From<std::string::String>>
          and 16 others   = note: required by `std::convert::From::from`

error[E0599]: no method named `tag` found for type `std::rc::Rc<markup5ever::rcdom::Node>` in the current scope
   --> src\main.rs:14:18
    | 14 |                 .tag("span")
    |                       ^^^ method not found in `std::rc::Rc<markup5ever::rcdom::Node>`
    |   = help: items from traits can only be used if the trait is in scope 
        = help: the following trait is implemented but not in scope, perhaps add a `use` for it:
    | 1  | use soup::handle_ext::HandleExt;
    |

该示例正在使用reqwest-0.9 (check soup的清单),而默认情况下它又使用旧的阻塞接口。

您正在使用reqwest-0.10,默认使用异步接口。这就是为什么你会得到一个Future in reqwest::get(...),这实际上并不意味着Try.

要么使用reqwest-0.9在您的依赖项中,使用reqwest::blocking::get() or request::get(...).await?与所有异步铃声和口哨声。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

没有为 impl 实现特质 std::ops::Try 的相关文章

随机推荐

  • 如何快速学习 Prism for Silverlight?

    我需要使用 Prism 制作 Silverlight 应用程序 学习使用 Silverlight Prism 制作简单应用程序的最佳方法是什么 还建议任何同样的好书 谢谢 我也有 daageu 提到的书 也会推荐它 但为了更快地加快学习 P
  • perl 子例程返回 array 和 str 但它们正在合并

    sub process feed my line my lines my last received while 1 if line push lines 1 line 2 else last received line last prin
  • 当文本字段等于字符串时,ios 使按钮更改视图

    我正在制作这种密码来跳过游戏中的关卡 但我不知道需要什么代码来使按钮更改视图控制器 IBAction button id sender if txt text isEqualToString passwordToSkipLevel1 Cod
  • 终止 Java 程序

    我找到了终止 关闭或停止 我的 Java 程序的方法 我找到了两个解决方案 using return 当我想退出或终止我的程序执行时 我添加这个 using 系统 exit 有时我也用过它 我读到系统 exit from 这个问题 所以 我
  • 锚标记的填充

    我有一个 asp net 页面 其代码如下所示
  • 我需要 ETL 吗?

    我们目前使用 Datastage ETL 每天导出包含 15 个表 3 个不同模式 中的数据的 CSV 文本文件 我想知道是否有一种更简单的方法可以在不使用 ETL 的情况下完成此任务 我尝试过脚本拉 它看起来简单 快速 但它又是一个 ET
  • 如何使用 objectMapper 设置 java.time.Instant 的字符串格式?

    我有一个实体java time Instant对于创建的数据字段 Getter Setter AllArgsConstructor NoArgsConstructor EqualsAndHashCode public class Item
  • Javafx 2.2 和雪豹

    我需要在 Mac 计算机上部署 JavaFX2 2 应用程序 OS X 10 7 或更高版本适用于 Java 7u7 OS X 10 6 怎么样 我们有什么解决办法吗 我认为 10 6 可以更新到 Java 6u35 并且我在某处读到 2
  • 如何从使用 /GL 编译的 .obj 文件确定主要编译器版本?

    我试图从以下位置确定 Visual Studio 版本 2002 2003 2005 2008 2010 2012 2013 2015 obj使用链接时间代码生成选项生成的文件 我使用 MSVC2012 生成的文件具有以下 COFF 标头内
  • 在 Javascript 中推送对象

    我需要在 Javascript 中将对象推送到数组 但每次推送都会覆盖我已经添加的相同对象 例如 This is object list var NewIssue This is array var newIssueList functio
  • 从索引的列/行数组填充出现次数矩阵

    我正在寻找一种有效的方法来从两个包含索引的数组创建出现矩阵 一个代表行索引在这个矩阵中 另一个是列矩阵 例如 我有 matrix will be size 4x3 in this example array of rows idxs wit
  • Python 中互斥锁的正确使用

    我从 python 中的多线程开始 或者至少我的脚本可能创建多个线程 这个算法是互斥体的正确用法吗 我还没有测试过这段代码 它可能根本无法工作 我只希望 processData 在一个线程中运行 一次一个 并且主 while 循环继续运行
  • 帐户仅限于 Google Classroom API

    我和我的同事有一个 C WPF 项目 它管理 Google Classroom 中的课程 我们在 Google API 平台中创建项目 我们是该项目的所有者 两者都有 OAuth 2 0 客户端 ID 但这并不重要 我允许 Classroo
  • 简单的 Spring Boot 应用程序中使用了哪种 ApplicationContext 实现?

    我学过 应用程序上下文 的三种常用实现是 FileSystemXmlApplicationContext 该容器加载定义 来自 XML 文件的 bean 这里需要提供完整路径 将 XML bean 配置文件传递给构造函数 ClassPath
  • 表达式中的变量赋值

    这是我的代码 用于生成斐波那契序列中低于 10 000 000 的值 3 fibs 1 1 4 while x fibs 1 fibs 2 lt 10000000 5 fibs append x 我尝试在 while 循环的条件中对 x 进
  • prolog 中的 if else if else 子句类似于 C/C++

    在 C 语言中我有类似的东西 if cond1 else if cond2 else 这在 Prolog 中怎么可能呢 If1 gt Then1 If2 gt Then2 otherwise 请注意 仅当您无法通过不同子句中的模式匹配来表达
  • 无法将 Web 项目添加到 tomcat 服务器“没有可以从服务器添加或删除的资源” - Java 17

    将 Eclipse 2021 9 工作区迁移到 Java 17 后 无法再将 Web 项目添加到 tomcat 服务器 Tomcat版本是9 0 54 所有项目都有 Project Facet 17 和相关的 java 17 JRE 此外
  • 如何在android中播放rtsp url?

    如何在android中播放rtsp url 你可以使用MediaPlayer or VideoView为此 它在模拟器中不起作用 你可以这样做 mediaplayer setDataSource String RTSP if you are
  • 在领域驱动设计中强制执行跨多个聚合的不变量(集验证)

    为了说明这个问题 我们使用一个简单的例子 有两个聚合 Lamp and Socket 必须始终执行以下业务规则 Lamp nor a Socket可以同时连接多次 为了提供适当的命令 我们设想了一个Connector 服务与Connect
  • 没有为 impl 实现特质 std::ops::Try

    我克隆了https gitlab com pwoolcoc soup并运行示例文件 一切正常 但是当我使用与示例文件相同的文件创建新项目时 遇到错误 代码是 use std collections HashSet use std fmt E