Rust 第三方库上的“未解决的导入”

cla*_*lay 5 import module rust rust-crates rust-cargo

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

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

[dependencies]
warp = "0.1.18"
Run Code Online (Sandbox Code Playgroud)

src/main.rs

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

[dependencies]
warp = "0.1.18"
Run Code Online (Sandbox Code Playgroud)

当我运行时,cargo build我看到它下载了 warp 和大量传递依赖项,然后出现错误:

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));
}
Run Code Online (Sandbox Code Playgroud)

我已经阅读了有关模块和板条箱的各种文档。在这个简单的场景中我做错了什么?

Kor*_*nel 6

您不小心将 Cargo 项目设置为向后兼容模式,该模式模拟该语言的旧“2015”版本。

为了能够使用正常的 Rust 语法,请添加:

edition = "2021"
Run Code Online (Sandbox Code Playgroud)

到你的Cargo.toml部分[package]

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