gpt4 book ai didi

import - 第三方库上的 Rust `unresolved import`

转载 作者:行者123 更新时间:2023-11-29 08:28:38 26 4
gpt4 key购买 nike

我想使用名为 warp 的第三方库编译一个简单的 Rust 程序:

[package]
name = "hello-world-warp"
version = "0.1.0"

[dependencies]
warp = "0.1.18"

src/main.rs 中:

use warp::{self, path, Filter};

fn main() {
// GET /hello/warp => 200 OK with body "Hello, warp!"
let hello = warp::path!("hello" / String)
.map(|name| format!("Hello, {}!", name));

warp::serve(hello)
.run(([127, 0, 0, 1], 3030));
}

当我运行 cargo build 时,我看到它下载了 warp 和许多传递依赖项,然后我得到了错误:

Compiling hello-world-warp v0.1.0 (<path>) error[E0432]: unresolved import `warp`
--> src/main.rs:3:12
|
3 | use warp::{self, path, Filter};
| ^^^^ no `warp` in the root

error: cannot find macro `path!` in this scope

我浏览了有关模块和箱子的各种文档。在这个简单的场景中我做错了什么?

最佳答案

您复制的示例使用的语法适用于最新版本的 Rust,但您不小心将 Rust 设置为模拟旧的“2015”版本的语言。

您必须添加:

edition = "2018"

到您的 Cargo.toml[package] 部分。

开始新项目时,始终使用cargo new。它将确保正确设置最新版本标志。

关于import - 第三方库上的 Rust `unresolved import`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57350520/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com