我正在尝试用 Rust 编译一个库,但出现错误:
error[E0670]: `async fn` is not permitted in Rust 2015
--> src/lib.rs:1:1
|
1 | async fn foo() {
| ^^^^^ to use `async fn`, switch to Rust 2018 or later
|
= help: set `edition = "2021"` in `Cargo.toml`
这是我的 Cargo.toml:
[package]
name = "name"
version = "0.1.0"
edition = "2018"
为了编译,我使用以下命令行(文档here):
rustc --crate-type=lib src/apis/my_file.rs
有人有想法吗?
顾名思义,
Cargo.toml
由cargo
解释,而不是rustc
,如果你想用rustc
编译,你必须添加版本标志:
rustc --edition=2018 --crate-type=lib src/apis/my_file.rs