相关文章推荐
贪玩的紫菜  ·  21-SQLServer临时表应用_哔哩哔哩 ...·  2 年前    · 
完美的抽屉  ·  大语言模型用到的代码库资源_大模型语料库构建 ...·  2 年前    · 
有腹肌的上铺  ·  【问题解决】AttributeError: ...·  2 年前    · 
乐观的滑板  ·  python3 ...·  3 年前    · 
重感情的苦瓜  ·  解决报错:jinja2.exceptions ...·  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
 
推荐文章
贪玩的紫菜  ·  21-SQLServer临时表应用_哔哩哔哩_bilibili
2 年前
完美的抽屉  ·  大语言模型用到的代码库资源_大模型语料库构建代码-CSDN博客
2 年前
有腹肌的上铺  ·  【问题解决】AttributeError: module ‘numpy.random‘ has no attribute ‘default_rng‘_51CTO博客_解决……问题
2 年前
乐观的滑板  ·  python3 dataframe写入oracle数据库,监听程序识别SID报错解决, - 简书
3 年前
重感情的苦瓜  ·  解决报错:jinja2.exceptions.TemplateNotFound: index.html_51CTO博客_解决报错14
3 年前
今天看啥   ·   Py中国   ·   codingpro   ·   小百科   ·   link之家   ·   卧龙AI搜索
删除内容请联系邮箱 2879853325@qq.com
Code - 代码工具平台
© 2024 ~ 沪ICP备11025650号