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

标签 rust rust-cargo rustup

使用 cargo new 创建新项目时,我想让 Cargo.toml 文件自动包含一个预定义的 authors field 。
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到我的环境变量。没用。
然后我尝试添加变量 nameemail在外地[cargo-new] , 关于 .cargo/config.toml配置文件并了解到它已被弃用。
有没有其他方法可以做到这一点?我做错什么了吗?
[package]
name = "hello_world"
version = "0.1.0"
edition = "2018"

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

[dependencies]
我正在使用 rustupnightly Arch Linux 上的工具链。

最佳答案

行为已在 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.


原来是authors crate list 中的 list 产生的问题多于它解决的问题,因为 list 是不可变的,而 crate 的作者不是。
所以截至今天,没有办法自动添加 authors在一个新的 cargo 项目上。

关于rust - 如何为新的 Cargo 项目设置默认作者?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67891784/

相关文章:

rust - 如何使 cargo 保存分析?

rust - 如何在Abs中实现Abs函数以自定义类型?

rust - cargo install 是否有等效的更新命令?

rust - 如何使用 [stdout] 和 [sterr] 作为 Command stdout 的前缀?

multithreading - 使用非重叠向量 block ,并合并结果

rust - 从实现Drop的结构中移动值时,如何避免不必要的匹配检查或使用不安全?

ios - 如何在不破坏 Rust 工具链的情况下在 XCode 中测试 iOS 应用程序?

rust - 无法从 conda 环境中的 jupyter 服务器连接到 rust 内核

rust - cargo 未能为rustc_version选择版本

regex - 在当前范围内找不到类型 `unwrap` 的名为 `regex::re::Regex` 的方法