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

Rust 开发环境安装

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

1.设置跟路径
设置环境变量RUST_HOME;
RUSTUP_HOME=%RUST_HOME%\.rustup
CARGO_HOME=%RUST_HOME%\.cargo
RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup
RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
RUST_BACKTRACE=1 //调试出错时打印详细调用栈

2.安装
2.1.安装版本
下载rustup-init.exe,在cmd中运行命令,选择1
安装完成后,运行rustup component add rls(否则Eclipse Corrosion中会提示Install missing rls component in Rustup)
在%CARGO_HOME%下创建config文件,内容如下,清华的镜像比较完整,中科大的非常不稳定。
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"

# 替换成你偏好的镜像源
# replace-with = 'sjtu'
replace-with = 'tuna'

# 清华大学
[source.tuna]
registry = "http://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"

# 中国科学技术大学
[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"

# 上海交通大学
[source.sjtu]
registry = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index"

# rustcc社区
[source.rustcc]
registry = "git://crates.rustcc.cn/crates.io-index"
2.2.安装rls
用于提示、自动完成等功能
rustup component add rls rust-analysis rust-src

2.3.创建工程
Cargo new 工程名称

2.4.测试运行
在项目下运行cargo build会按照cargo.toml中的设置,开始编译
运行cargo run,就会运行,默认运行debug版,性能会比较弱,用cargo run --release会大幅度提升性能,注意后面的是“--release”,不能省掉“--”

2.5.Blocking错误
如果编译被异常终止,导致cargo进程被吊死,不能释放.cargo/.package-cache。这种情况下首先要停止所有的cargo进程,同时删除.cargo/.package-cache文件。
有时候,vscode也会锁住cargo build,还没找出规律。
3.VSCode开发环境
3.1.安装rust插件
在扩展中搜索rust,安装rust相关插件


3.2.调试
Windows下安装C\C++ for Visual Studio Code,其他OS安装CodeLLDB(没有亲自试过)。注意,Windows下是安装这个,否则不能单步跟踪。

手动修改.vscode/launch.json,type改为cppvsdbg,增加program,按F5就可以单步跟踪了。
 "configurations": [
  {
        "type": "cppvsdbg",
        "program": "${workspaceRoot}/target/debug/xxx.exe",
...
}

4.开发
4.1.注意事项
最后的返回值表达式,不能加分号

4.2.常用库
1.模板引擎:https://github.com/botika/yarte
2.日志:https://github.com/estk/log4rs
3.Web框架:https://github.com/http-rs/tide
4.Web 框架:https://chrismorgan.info/blog/introducing-teepee/ 从rust-http演变而来
5.Http3 Web框架:https://github.com/mozilla/neqo
6.Crypto库,基于BoringSSL:https://github.com/briansmith/ring
7.其他:https://zhuanlan.zhihu.com/p/62325234


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
设置matlab的默认属性发布时间:2022-07-18
下一篇:
MatLab GUI Use Command for Debug 界面调试的一些方法发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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