Working through Rust's Getting Started page on macOS, I ran the following command for Cargo to generate a project:
cargo new hello_world --bin
When I inspected the Cargo.toml
file, it contained my real name as well as my email address.
From where is Cargo getting my name and email? How can I configure the name and email address Cargo uses?
Cargo can also be configured through environment variables in addition to the TOML configuration files. For each configuration key of the form foo. bar the environment variable CARGO_FOO_BAR can also be used to define the value.
Cargo. toml and Cargo. lock are stored in the root of your project (package root). Source code goes in the src directory.
Cargo. toml is the manifest file for Rust's package manager, cargo . This file contains metadata such as name, version, and dependencies for packages, which are call "crates" in Rust.
Cargo is a Build System and Package manager of Rust. like pip in Python or npm in JavaScript. This means, cargo is a tool that makes us easily download external crates or manage dependencies with a single line command.
Cargo uses your git configuration, among other environment variables.
To override it, you should be able to set the CARGO_EMAIL
and CARGO_NAME
environment variables when running cargo. E.g:
CARGO_NAME=not-ross cargo new --bin project_name
For example:
simon /c/rust
$ CARGO_NAME=Not-Simon CARGO_EMAIL=not_simon@not_simon.com cargo new --bin override-author
Created binary (application) `override-author` project
simon /c/rust
$ cd !$
simon /c/rust/override-author (master)
$ cat Cargo.toml
[package]
name = "override-author"
version = "0.1.0"
authors = ["Not-Simon <not_simon@not_simon.com>"]
[dependencies]
Using CARGO_NAME
and CARGO_EMAIL
lets cargo
figure out the author name and email at a higher "scope". Looking at the code in more detail, it will check git first but you can override it with the --vcs
flag which will still use CARGO_NAME
and CARGO_EMAIL
if provided.
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