Let’s revisit & deepen our knowledge of a few areas.
A Cargo package can (at the same time) contain:
0 or 1 library crates
0..n binary crates
it must contain at least one crate in total.
The default binary is the main()
function in src/main.rs
.
Additional binaries are stored in the src/bin/
directory.
Example binaries are located in examples/
.
By default, the library crate is implemented in src/lib.rs
and has the same module name as the package.
Cargo can be extended:
cargo-tree
: show dependency graph
cargo-edit
: add/remove/upgrade dependencies
cargo-watch
: recompile/restart project on change
and many more.
https://crates.io is the public crates registry. Dependencies specified by version only in Cargo.toml
will be downloaded and installed from there.
Cargo also allows you to specify git
or path
(local) dependencies:
rand = { git = "https://github.com/rust-lang-nursery/rand", branch = "next" }
hello_utils = { path = "hello_utils" }
Rudimentary handling can be done using std::env::args
A feature-rich alternative is structopt.