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


参考

相关推荐
云帆小二15 分钟前
从开发语言出发如何选择学习考试系统
开发语言·学习
光泽雨35 分钟前
python学习基础
开发语言·数据库·python
q***49861 小时前
数据库操作与数据管理——Rust 与 SQLite 的集成
数据库·rust·sqlite
百***06011 小时前
python爬虫——爬取全年天气数据并做可视化分析
开发语言·爬虫·python
jghhh012 小时前
基于幅度的和差测角程序
开发语言·matlab
fruge2 小时前
自制浏览器插件:实现网页内容高亮、自动整理收藏夹功能
开发语言·前端·javascript
曹牧2 小时前
Java中处理URL转义并下载PDF文件
java·开发语言·pdf
未来之窗软件服务2 小时前
幽冥大陆(二十二)dark语言智慧农业电子秤读取——东方仙盟炼气期
开发语言·windows·golang·东方仙盟·东方仙盟sdk
逐步前行2 小时前
C项目--羊了个羊(两关全)--含源码
c语言·开发语言
IMPYLH3 小时前
Lua 的 assert 函数
开发语言·笔记·junit·单元测试·lua