本文采用知识共享署名 4.0 国际许可协议进行许可,转载时请注明原文链接,图片在使用时请保留全部内容,可适当缩放并在引用处附上图片所在的文章链接。
Rust 程序设计语言 中文版
安装
- rust
Getting started
1
2
3
4
5
6
7
8
9
10
11
|
# 安装
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh
# 升级
rustup update
# 卸载
rustup self uninstall
# 查看版本
rustc --version
|
- vscode
插件:rust-analyzer : Rust 语言服务器 (RLS) 已被弃用,取而代之的是 rust-analyzer。RLS 用户应该改用 rust-analyzer。 (2022-07-02)
编译运行
- rustc
rustc 只适合简单的程序。
- cargo
Cargo 是 Rust 的构建系统和包管理器。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# 查看版本
cargo --version
# 构建项目
cargo new hello_cargo
cd hello_cargo
# 构建了项目,并使用 ./target/debug/hello_cargo 运行了程序
cargo build
# cargo run 在一个命令中同时编译代码并运行生成的可执行文件
cargo run
# 快速检查代码确保其可以编译,但并不产生可执行文件
cargo check
# 优化编译项目
cargo build --release
cargo build --debug
|
使用 Cargo 当作习惯
1
2
3
|
git clone example.org/someproject
cd someproject
cargo build
|