Rust: Cargo.toml error: expected item, found `[`, when trying to include nalgebra

Rust: Cargo.toml error: expected item, found `[`, when trying to include nalgebra

[package]
name = "my package"
version = "0.1.0"
authors = ["me"]
edition = "2018"

[dependencies]
nalgebra = "0.18.1"

我尝试用上面的 Cargo.toml 编译 rust 但它给了我以下错误:

error: expected item, found `[`
 --> Cargo.toml:1:1
  |
1 | [package]
  | ^ expected item

error: aborting due to previous error

如果我删除 nalgebra = "0.18.1",我可以解决这个问题,但我不能使用 nalgebra 包,所以它对我没有帮助。

我认为您的 Cargo.toml

存在多个问题

这是不允许的:

name = "my package"

建议:

name = "my-package"

还有缺失的部分:

error during execution of `cargo metadata`: error: failed to parse manifest at `test/Cargo.toml`

Caused by:
  no targets specified in the manifest
  either src/lib.rs, src/main.rs, a [lib] section, or [[bin]] section must be present

你能post这里的整个文件吗?

最小可行设置:

[package]
name = "my-package"
version = "0.1.0"
authors = ["me"]
edition = "2018"

[[bin]]
name = "radkilla"
path = "src/main.rs"
doc = false

[dependencies]
nalgebra = "0.18.1"

src/main.rs

fn main() {}

运行 fmt 和构建:

➜  test cargo fmt ; cargo build
    Finished dev [unoptimized + debuginfo] target(s) in 0.11s

关闭在 visual studio 打开的 cargo.toml 文件后错误消失。