Import 对第三方库执行“未解析导入”。新手问题

Import 对第三方库执行“未解析导入”。新手问题,import,module,rust,rust-cargo,rust-crates,Import,Module,Rust,Rust Cargo,Rust Crates,我想使用名为warp的第三方库编译一个简单的rust程序: [package] name = "hello-world-warp" version = "0.1.0" [dependencies] warp = "0.1.18" 在src/main.rs中: 使用warp::{self,path,Filter}; fn main(){ //GET/hello/warp=>200 OK,正文为“hello,warp!” 让hello=warp::path!(“hello”/String) .m

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

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

[dependencies]
warp = "0.1.18"
src/main.rs
中:

使用warp::{self,path,Filter};
fn main(){
//GET/hello/warp=>200 OK,正文为“hello,warp!”
让hello=warp::path!(“hello”/String)
.map(| name | format!(“你好,{}!”,name));
warp::serve(你好)
.运行([127,0,0,1],3030));
}
当我运行
cargo build
时,我看到它下载了warp和许多可传递的依赖项,然后我得到了错误:

编译hello world warp v0.1.0()错误[E0432]:未解析的导入`warp` -->src/main.rs:3:12 | 3 |使用warp:{self,path,Filter}; |^^^^根目录中没有“warp” 错误:找不到宏“路径!”在这个范围内
我查阅了关于模块和板条箱的各种文件。在这个简单的场景中,我做错了什么?

您复制的示例使用的语法在Rust的最新版本中有效,但您不小心将Rust设置为模仿该语言的旧“2015”版本

您必须添加:

edition = "2018"
到您的
Cargo.toml
[package]
部分


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

如果删除
self
,会发生什么情况?请注意,无论如何它都不是真正需要的,因为它已经在范围内(至少在Rust 2018中)。如果您不想指定
extern板条箱
,则需要使用2018版,并将
edition=“2018”
添加到
货物中。toml
。哇,就是这样:)而无需其他更改,它就可以工作了!谢谢