cargo usage
creating a new package
To start a new package with Cargo, use Cargo new
Bash展开
12
$ Cargo new <binary name> # for new binary
$ Cargo new <library name> --lib # for new library
This also initializes a new repository by default, and you can use --vcs none to disable it
add dependency
If your Cargo.toml doesn't already have a [dependencies] section, add that, then list the crate name and version that you would like to use. This example adds a dependency of the time crate:
PlainText展开
12
[dependencies] time="3.1.2"
Then use cargo build, cargo will fetch the new dependency and compile them , and update Cargo.lock file.