When creating a new project with cargo new
, I would like to have the Cargo.toml file automatically include a predefined authors
field.
The 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.
It was pretty vague, so I searched about it. First I tried adding CARGO_NAME
and CARGO_EMAIL
to my environment variables. Didn't work.
Then I tried adding the variables name
and email
in the field [cargo-new]
, on the .cargo/config.toml
config file and learned it is deprecated.
Are there any other ways to do this? Did I do something wrong?
[package]
name = "hello_world"
version = "0.1.0"
edition = "2018"
authors = ["foo <[email protected]>"] # Add this line automatically
[dependencies]
I'm using rustup
with the nightly
toolchain on Arch Linux.
The behaviour was changed in RFC 3052, implemented in Cargo 1.53. From the 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.
It turned out that the authors
list in a crate's manifest created more problems than it solved, because the manifest is immutable, while the authors of a crate are not.
So as of today, there is no way to automatically add authors
on a new cargo project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With