相关文章推荐
风流的啄木鸟  ·  接口中的方法访问权限不可是protected ...·  11 月前    · 
重感情的围巾  ·  module 'torch' has no ...·  1 年前    · 
文雅的橡皮擦  ·  Logstash笔记(三)----Filte ...·  2 年前    · 
聪明伶俐的泡面  ·  python协程总结 - fengf233 ...·  2 年前    · 
果断的麻辣香锅  ·  万字长文把 VSCode 打造成 C++ ...·  2 年前    · 
Code  ›  错误:无法在tokio中找到main或io,无效的返回类型“`impl Future”开发者社区
tokio
https://cloud.tencent.com/developer/ask/sof/107803961
侠义非凡的脆皮肠
4 月前
首页
学习
活动
专区
圈层
工具
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
 
推荐文章
风流的啄木鸟  ·  接口中的方法访问权限不可是protected_接口中的方法可以声明为protected吗-CSDN博客
11 月前
重感情的围巾  ·  module 'torch' has no attribute 'softmax'_Python-CSDN问答
1 年前
文雅的橡皮擦  ·  Logstash笔记(三)----Filter插件及grok的正则表达式来解析日志-阿里云开发者社区
2 年前
聪明伶俐的泡面  ·  python协程总结 - fengf233 - 博客园
2 年前
果断的麻辣香锅  ·  万字长文把 VSCode 打造成 C++ 开发利器 - 知乎
2 年前
今天看啥   ·   Py中国   ·   codingpro   ·   小百科   ·   link之家   ·   卧龙AI搜索
删除内容请联系邮箱 2879853325@qq.com
Code - 代码工具平台
© 2024 ~ 沪ICP备11025650号