2024 Rust现代实用教程:1.3获取rust的库国内源以及windows下的操作

文章目录

一、使用Cargo第三方库

1.直接修改Cargo.toml

rust语言的库:crate

黏贴至Cargo.toml

  • 保存完毕之后,自动下载依赖

拷贝crate中的ducument的代码进行测试

2.使用cargo-edit插件

安装

  • cargo install cargo-edit

添加库

  • cargo add dependency_name

安装指定版本

  • cargo add dependency_name@1.2.3

添加开发时用的依赖库

  • cargo add --dev dev_dependency_name

添加构建时用的依赖库

  • cargo add --build build dependency na-me

删除库

  • cargo rm dependency_name,删除[dependencies]中依赖的包
  • cargo rm --dev dependency_name,删除[dev-dependencies]中依赖的包

eg:

安装最新的rand包

bash 复制代码
▶ cargo add rand

安装特定版本的rand

安装到[dev-dependencies]

删除最新的rand包

3.设置国内源

RsProxy

bash 复制代码
▶ cat  ~/.cargo/config
[source.crates-io]
replace-with = 'rsproxy-sparse'
[source.rsproxy]
registry = "https://rsproxy.cn/crates.io-index"
[source.rsproxy-sparse]
registry = "sparse+https://rsproxy.cn/index/"
[registries.rsproxy]
index = "https://rsproxy.cn/crates.io-index"
[net]
git-fetch-with-cli = true
➜ ~ ⚡   

warning: /home/wangji/.cargo/config is deprecated in favor of config.toml

解决办法:▶ mv /home/wangji/.cargo/config /home/wangji/.cargo/config.toml

4.与windows下面的rust不同点

安装方式不同

windows可选Rust的目标平台标识

  • x86 64-pc-windows-msvc
  • x86_64-pc-windows-.gnu(不推荐)

ustup component

  • 某些组件可能不同

设置国内源的文件路径不同

  • C.\Users<你的用户名>l.cargo\config


参考

相关推荐
倔强青铜34 小时前
苦练Python第18天:Python异常处理锦囊
开发语言·python
u_topian4 小时前
【个人笔记】Qt使用的一些易错问题
开发语言·笔记·qt
珊瑚里的鱼5 小时前
LeetCode 692题解 | 前K个高频单词
开发语言·c++·算法·leetcode·职场和发展·学习方法
AI+程序员在路上5 小时前
QTextCodec的功能及其在Qt5及Qt6中的演变
开发语言·c++·qt
xingshanchang5 小时前
Matlab的命令行窗口内容的记录-利用diary记录日志/保存命令窗口输出
开发语言·matlab
Risehuxyc5 小时前
C++卸载了会影响电脑正常使用吗?解析C++运行库的作用与卸载后果
开发语言·c++
AI视觉网奇5 小时前
git 访问 github
运维·开发语言·docker
不知道叫什么呀5 小时前
【C】vector和array的区别
java·c语言·开发语言·aigc
liulilittle6 小时前
.NET ExpandoObject 技术原理解析
开发语言·网络·windows·c#·.net·net·动态编程
wan_da_ren6 小时前
JVM监控及诊断工具-GUI篇
java·开发语言·jvm·后端