01-rust环境搭建

  1. 1.安装rustup
  2. 2.安装vsocode插件
  3. 3.运行hello world!
  4. 4.修改 Rust 的下载镜像为国内的镜像地址

当前环境:win11+wsl+vscode

1.安装rustup

1
2
3
4
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh
sudo apt install build-essential
rustc -V
cargo -V

2.安装vsocode插件

1
2
3
4
5
rust-analyzer ,Rust 语言插件
Even Better TOML,支持 .toml 文件完整特性
Error Lens, 更好的获得错误展示
One Dark Pro, 非常好看的 VSCode 主题
CodeLLDB, Debugger 程序

3.运行hello world!

1
2
3
4
5
6
7
8
9
10
cargo new world_hello
cd world_hello
cargo run
#编译
cargo build
#运行
./target/debug/world_hello
Hello, world!
#快速的检查一下代码能否编译通过
cargo check

4.修改 Rust 的下载镜像为国内的镜像地址

1
2
3
4
5
6
7
#在 $HOME/.cargo/config.toml 添加以下内容:

[source.crates-io]
replace-with = 'ustc'

[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"

转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 yengii@qq.com