安装 Rust
参照官方文档, 安装文档
Cargo: Rust 的构建工具和包管理器
cargo build
可以构建项目cargo run
可以运行项目cargo test
可以测试项目cargo doc
可以为项目构建文档cargo publish
可以将库发布到 crates.io。
Cargo 更换国内源
- 中科大源
- linux
tee $HOME/.cargo/config <<-'EOF' [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" EOF
- Windows
在
C:\Users\user\.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" EOF
卸载Rust
rustup self uninstall
相关问题
1. 在Windows wsl 里 run
error: linker cc
not found
Compiling hello-rust v0.1.0 (/home/rust/hello-rust)
error: linker `cc` not found
|
= note: No such file or directory (os error 2)
error: aborting due to previous error
error: could not compile `hello-rust`
To learn more, run the command again with --verbose.
原因缺少 gcc 解决方案
sudo apt-get update
sudo apt install build-essential
相关链接
Rust 2021
- 安装最近的nightly:
rustup update nightl
y. - 运行
cargo +nightly fix --edition
。 - 编辑Cargo.toml并放置cargo-features = ["edition2021"]在顶部(上方[package]),并将编辑字段更改为edition = "2021"。
- 运行
cargo +nightly check
以验证它现在可以在新版本中使用。