Rust 基础大纲
1.Summary
安装
https://www.rust-lang.org/zh-CN/tools/install
bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# 安装完成后,验证是否成功
rustc -V
cargo -V
# 创建项目
cargo new my_project
# 编译项目
cargo build
# 生成的可执行文件位于 target/debug/ 目录下。
# 运行程序
# 直接运行以下命令:
cargo run

教材
- 英文:https://doc.rust-lang.org/book/
- Can also open it locally: rustup docs --book
- 中文:https://kaisery.github.io/trpl-zh-cn/title-page.html
rust by practicehttps://practice.rs/
rust by exampleshttps://doc.rust-lang.org/stable/rust-by-example/
rust 圣经https://course.rs/about-book.html
rust 官方文档中文网站https://rustwiki.org/
Experiment: Improving the Rust Book
2 Rust 源
中国区,可能连接 crates.io 会有问题。
在 $HOME/.cargo/config
中添加如下内容:
bash
[source.crates-io]
replace-with = 'ustc'
[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"
如果所处的环境中不允许使用 git 协议,可以把上述地址改为:
bash
registry = "https://mirrors.ustc.edu.cn/crates.io-index"
2.1 cargo 版本>= 1.68 支持稀疏索引
可以在 $HOME/.cargo/config
中添加如下内容:
cargo 1.68 版本开始支持稀疏索引:不再需要完整克隆 crates.io-index 仓库,可以加快获取包的速度。
bash
[source.crates-io]
replace-with = 'ustc'
[source.ustc]
registry = "sparse+https://mirrors.ustc.edu.cn/crates.io-index/"