Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does Cargo get my name and email from when creating a project?

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?

like image 283
ross Avatar asked Jan 08 '17 23:01

ross


People also ask

How do you set up cargo?

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.

Where is my cargo toml file?

Cargo. toml and Cargo. lock are stored in the root of your project (package root). Source code goes in the src directory.

What is a cargo toml file?

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.

What is cargo bin 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.


1 Answers

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.

like image 171
Simon Whitehead Avatar answered Oct 22 '22 13:10

Simon Whitehead