Rust 及其包管理Cargo的安装使用


Rust 公众号 https://mp.weixin.qq.com/s/aRGY6oLXVQzxbb1wb3RGcA
Rust 中文社区教程 https://rustcc.gitbooks.io/rustprimer/content/quickstart/rust-travel.html

安装

see more: https://www.rust-lang.org/zh-CN/tools/install

$CARGO_HOME/config.toml which defaults to:

    Windows: %USERPROFILE%\.cargo\config.toml
    Unix: $HOME/.cargo/config.toml

Note: Cargo also reads config files without the .toml extension, such as .cargo/config. Support for the .toml extension was added in version 1.39 and is the preferred form. If both files exist, Cargo will use the file without the extension.

在 config 文件中添加如下内容:

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

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

如果所处的环境中不允许使用 git 协议,可以把上述地址改为:

registry = "https://mirrors.ustc.edu.cn/crates.io-index"

  1. https://mirrors.ustc.edu.cn/help/crates.io-index.html

  2. https://doc.rust-lang.org/cargo/reference/config.html

其他镜像源:
https://rsproxy.cn

更新 Rust

network-proxy https://rust-lang.github.io/rustup/network-proxies.html

## 官方直连
rustup update

## 使用镜像源 see: https://mirrors.ustc.edu.cn/help/rust-static.html
# PowerShell
$env:RUSTUP_DIST_SERVER="https://mirrors.ustc.edu.cn/rust-static"
$env:RUSTUP_UPDATE_ROOT="https://mirrors.ustc.edu.cn/rust-static/rustup"
rustup update

初始化当前目录为Rust项目

cargo install

更新项目依赖

cargo update

开发环境

VSCode + Rust

WEB 框架

Rocket
actix-web

我的一些代码片段

  1. 获得项目某个子目录下的绝对地址 (Rust 1.54)
	// 获得当前项目目录下的 web_driver 目录完整路径(系统无关)
    let mut dir = env::current_dir().unwrap().as_path().join("web_driver");
	// 获得以上路径的系统路径
    let mut current_dir = fs::canonicalize(dir).unwrap();

结果(调试)
image


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM