相关文章推荐
豪情万千的台灯  ·  复杂JSON数据加工_日志服务(SLS)-阿 ...·  1 年前    · 
爽快的墨镜  ·  关于Mysql某一个区间的查询 - CSDN文库·  2 年前    · 
耍酷的自行车  ·  在c#中的TextBox响应回车键发出“咚” ...·  2 年前    · 
愤怒的毛巾  ·  篇二、CFD ...·  3 年前    · 
没读研的日记本  ·  SystemVerilog——字符串类型_p ...·  3 年前    · 
Code  ›  错误:无法在tokio中找到main或io,无效的返回类型“`impl Future”开发者社区
tokio
https://cloud.tencent.com/developer/ask/sof/107803961
侠义非凡的脆皮肠
1 年前
首页
学习
活动
专区
圈层
工具
MCP广场
返回腾讯云官网
提问

问 错误:无法在tokio中找到main或io,无效的返回类型“`impl Future”

Stack Overflow用户
提问于 2021-02-26 14:43:06
EN

我正准备从ML家族转到Rust,但我发现在一些陌生的地方,我不习惯遇到问题。

我试图使用 hyper 进行http处理,但似乎无法让 tokio 工作。

我试过复制粘贴这个 示例

代码语言: javascript
运行
复制
use hyper::{body::HttpBody as _, Client};
use tokio::io::{self, AsyncWriteExt as _};
type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
#[tokio::main]
async fn main() -> Result<()> {
    // ...
    fetch_url(url).await
async fn fetch_url(url: hyper::Uri) -> Result<()> {
    // ...
    Ok(())
}

这是我的 Cargo.toml

代码语言: javascript
运行
复制
[package]
name = "projectname"
version = "0.1.0"
authors = ["username"]
edition = "2018"
[dependencies]
hyper = "0.14.4"
tokio = "1.2.0"

它在抱怨它找不到 io 机箱, main 有一个无效的 impl Future 类型,并且在 tokio 中找不到 main

代码语言: javascript
运行
复制
error[E0433]: failed to resolve: could not find `main` in `tokio`
 --> src/main.rs:9:10
9 | #[tokio::main]
  |          ^^^^ could not find `main` in `tokio`
error[E0277]: `main` has invalid return type `impl Future`
  --> src/main.rs:10:20
10 | async fn main() -> Result<()> {
   |                    ^^^^^^^^^^ `main` can only return types that implement `Termination`
error[E0432]: unresolved import `hyper::Client`
 --> src/main.rs:3:34
3 | use hyper::{body::HttpBody as _, Client};
  |                                  ^^^^^^ no `Client` in the root
error[E0425]: cannot find function `stdout` in module `io`
  --> src/main.rs:45:13
45 |         io::stdout().write_all(&chunk).await?;
   |             ^^^^^^ not found in `io`
error[E0432]: unresolved import `tokio::io::AsyncWriteExt`
 --> src/main.rs:4:23
 
推荐文章
豪情万千的台灯  ·  复杂JSON数据加工_日志服务(SLS)-阿里云帮助中心
1 年前
爽快的墨镜  ·  关于Mysql某一个区间的查询 - CSDN文库
2 年前
耍酷的自行车  ·  在c#中的TextBox响应回车键发出“咚”的一声解决方法 - 落枫飘飘 - 博客园
2 年前
愤怒的毛巾  ·  篇二、CFD CODING之后处理(python)续 - 知乎
3 年前
没读研的日记本  ·  SystemVerilog——字符串类型_psprintf systemverilog_劲仔小鱼的博客-CSDN博客
3 年前
今天看啥   ·   Py中国   ·   codingpro   ·   小百科   ·   link之家   ·   卧龙AI搜索
删除内容请联系邮箱 2879853325@qq.com
Code - 代码工具平台
© 2024 ~ 沪ICP备11025650号