相关文章推荐
飘逸的饭卡  ·  python移动文件问题 - ...·  5 月前    · 
文雅的数据线  ·  基于位表示的8叉树数据存储原理_八叉树存储- ...·  1 年前    · 
没读研的毛衣  ·  node js image url to ...·  1 年前    · 
逃跑的企鹅  ·  与时间赛跑的人——钟扬教授的两个昼夜(报告文 ...·  1 年前    · 
重感情的热水瓶  ·  WPS ...·  1 年前    · 
Code  ›  错误:无法在tokio中找到main或io,无效的返回类型“`impl Future”开发者社区
tokio
https://cloud.tencent.com/developer/ask/sof/107803961
侠义非凡的脆皮肠
3 天前
首页
学习
活动
专区
圈层
工具
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
 
推荐文章
飘逸的饭卡  ·  python移动文件问题 - zhangyao2018 - 博客园
5 月前
文雅的数据线  ·  基于位表示的8叉树数据存储原理_八叉树存储-CSDN博客
1 年前
没读研的毛衣  ·  node js image url to base64-掘金
1 年前
逃跑的企鹅  ·  与时间赛跑的人——钟扬教授的两个昼夜(报告文学) - 中华人民共和国教育部政府门户网站
1 年前
重感情的热水瓶  ·  WPS EXCEL制作二级下拉框、动态下拉框、联动下拉框_一级下拉框动态二级跟着调整_学习要趁早z的博客-CSDN博客
1 年前
今天看啥   ·   Py中国   ·   codingpro   ·   小百科   ·   link之家   ·   卧龙AI搜索
删除内容请联系邮箱 2879853325@qq.com
Code - 代码工具平台
© 2024 ~ 沪ICP备11025650号