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


参考

相关推荐
qq_3363139311 分钟前
java基础-IO流(打印流)
java·开发语言
缺点内向11 分钟前
C#: 精准掌控Excel工作流——激活工作表与选择单元格实战
开发语言·c#·excel
峥无39 分钟前
《二叉搜索树:动态数据管理的利器,平衡树的基石》
开发语言·c++·二叉搜索树
CoderCodingNo40 分钟前
【GESP】C++五级真题(数论, 贪心思想考点) luogu-B4070 [GESP202412 五级] 奇妙数字
开发语言·c++·算法
一刻钟.1 小时前
DataGridView和定时器
开发语言·c#
墨辰JC1 小时前
C语言可变参数讲解:stdarg.h应用
c语言·开发语言·蓝桥杯·内存·蓝桥杯嵌入式
L1624761 小时前
Windows 系统下 ZIP安装MySQL 详细操作步骤
数据库·windows·mysql
Larry_Yanan1 小时前
Qt多进程(八)消息队列(基于文件)
开发语言·qt
毕设源码-钟学长1 小时前
【开题答辩全过程】以 基于java旅游网站的设计与实现为例,包含答辩的问题和答案
java·开发语言·旅游
0和1的舞者1 小时前
接口自动化测试详解(二):requests 请求封装与 Pytest 框架全实战
开发语言·自动化测试·python·测试开发·接口·测试