Command Line Applications in Rust
Rustup #
Rustup: the Rust installer and version management tool
通过 Rustup 安装 Rust 并管理不同版本。
Cargo #
the Rust build tool and package manager
When you install Rustup you’ll also get the latest stable version of the Rust build tool and package manager, also known as Cargo. Cargo does lots of things:
- build your project with
cargo build
- run your project with
cargo run
- test your project with
cargo test
- build documentation for your project with
cargo doc
- publish a library to crates.io with
cargo publish
当项目最终准备好发布时,可以使用 cargo build --release
来优化编译项目。
使用 Cargo,在组织代码结构时通常会将代码放在 src
目录下面。
rustc 命令 #
如果不用 Cargo,可以通过 rustc main.rs
编译程序并输出可执行文件 main
,然后直接 ./main
执行。