如何告诉 Cargo 使用 nightly?

Tom*_*ton 18 rust rust-cargo

我知道我可以通过运行每晚在项目上设置 Rust rustup override set nightly。但我想知道是否可以在 Cargo.toml 上声明它,所以如果我在另一台机器上构建,它将从一开始就以 nightly 运行。到目前为止我还没有找到一种方法来做到这一点。

Sör*_*ren 33

根据文档,不可能在Cargo.toml文件中指定它。但是您可以创建一个名为的新文件,rust-toolchain.toml其中包含以下内容:

[toolchain]
channel = "nightly"
Run Code Online (Sandbox Code Playgroud)

有关更多选项,请参阅同一文档中的工具链文件部分。

  • 在这些情况下,工具链可以在项目目录中名为 rust-toolchain.toml 或 rust-toolchain 的文件中命名。如果两个文件都存在于一个目录中,则后者用于向后兼容。``` https://rust-lang.github.io/rustup/overrides.html#the-toolchain-file 两者都是 `rust-toolchain.toml ` 和 `rust-toolchain` 有效。在文档中,“rust-toolchain”被称为“legacy”,因此首选文件应该是“rust-toolchain.toml”。 (3认同)