1.安装rustup (安装稳定版)
$ curl https://sh.rustup.rs -sSf | sh
注意:这里需要翻墙才可以访问
2.设置代理(国内访问要设置否则下载慢)
$ vim ~/.cargo/config
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = 'ustc'
[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"
粘贴后按esc 输入“:wq” 回车保存
3.安装工具,由于以下工具默认安装里存在占位程序,需要使用 --force 选项强制安装。
$ cargo install racer
$ cargo install --force rustfmt
$ cargo install --force rls
4.组件安装
$ rustup component add rls-preview rust-analysis rust-src
5.安装 VSCode Rust 扩展
打开 VSCode,在扩展中心搜索 Rust,安装第一个 Rust(rls) 即可。 安装完成后需要在 VSCode 中设置 rust-client.channel 为 stable。 同时建议设置 editor.formatOnSave 为 true,以便在保存时使用 rust-fmt 格式化代码。
注意:一定不要同时有多个 Rust 扩展,需要先将其他 Rust 扩展卸载,以防出问题。
6.创建新项目用vscode测试是否可以格式化代码
$ cargo new test && cd test
注意:这里必须用cargo new test 来创建项目,否则格式化没作用。