如何为新 Cargo 项目设置默认作者?

How can I set default authors for new Cargo projects?

使用 cargo new 创建新项目时,我希望 Cargo.toml 文件自动包含一个预定义的 authors 字段。

Rust book said:

The next four lines set the configuration information Cargo needs to compile your program: the name, the version, who wrote it, and the edition of Rust to use. Cargo gets your name and email information from your environment, so if that information is not correct, fix the information now and then save the file.

它很模糊,所以我搜索了一下。首先,我尝试将 CARGO_NAMECARGO_EMAIL 添加到我的环境变量中。没用。

然后我尝试在 .cargo/config.toml 配置文件的字段 [cargo-new] 中添加变量 nameemail,但发现它已被弃用。

还有其他方法吗?我是不是做错了什么?

[package]
name = "hello_world"
version = "0.1.0"
edition = "2018"

authors = ["foo <bar@gmail.com>"] # Add this line automatically

[dependencies]

我在 Arch Linux 上使用 rustupnightly 工具链。

行为已在 RFC 3052 中更改,在 Cargo 1.53 中实现。来自 RFC:

cargo init will stop pre-populating the field when running the command, and it will not include the field at all in the default Cargo.toml. Crate authors will still be able to manually include the field before publishing if they so choose.

事实证明,crate 清单中的 authors 列表造成的问题多于解决的问题,因为清单是不可变的,而 crate 的作者不是。

所以到今天为止,无法在新的货运项目上自动添加 authors