• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

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

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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();

结果(调试)


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap