该篇文章记录了 Rust 相关的命令,以便不时之需。

1. rustc –version

查看 rust 的版本号

1
$ rustc --version

2. rustup update

更新 rust 版本

1
$ rustup update

3. rustup doc

打开本地文档

1
$ rustup doc

4. 创建 Rust 项目

rust 项目的创建使用 cargo 工具生成管理的。

  • cargo new hello_rust 创建项目(可执行)
  • cargo build 编译项目
  • cargo check 检查项目
  • cargo run 运行项目
  • cargo build –release 以 Release 模式编译
  • cargo run –release 以 Release 模式运行

5. 查看命令帮助

cargo new –help,可以查看该命令相关的帮助。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
$ cargo new --help
cargo.exe-new
Create a new cargo package at <path>

USAGE:
cargo.exe new [OPTIONS] <path>

ARGS:
<path>

OPTIONS:
-q, --quiet Do not print cargo log messages
--registry <REGISTRY> Registry to use
--vcs <VCS> Initialize a new repository for the given version control system
(git, hg, pijul, or fossil) or do not initialize any version
control at all (none), overriding a global configuration. [possible
values: git, hg, pijul, fossil, none]
--bin Use a binary (application) template [default]
-v, --verbose Use verbose output (-vv very verbose/build.rs output)
--lib Use a library template
--color <WHEN> Coloring: auto, always, never
--edition <YEAR> Edition to set for the crate generated [possible values: 2015,
2018, 2021]
--frozen Require Cargo.lock and cache are up to date
--name <NAME> Set the resulting package name, defaults to the directory name
--locked Require Cargo.lock is up to date
--offline Run without accessing the network
--config <KEY=VALUE> Override a configuration value (unstable)
-Z <FLAG> Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for
details
-h, --help Print help information

Run `cargo help new` for more detailed information.