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


参考

相关推荐
集成显卡2 小时前
windows 下使用 bat 批处理运行 Chrome 无头模式刷一波访问量
windows·程序员
该用户已不存在2 天前
Mojo vs Python vs Rust: 2025年搞AI,该学哪个?
后端·python·rust
大卫小东(Sheldon)2 天前
写了一个BBP算法的实现库,欢迎讨论
数学·rust
侃侃_天下2 天前
最终的信号类
开发语言·c++·算法
echoarts2 天前
Rayon Rust中的数据并行库入门教程
开发语言·其他·算法·rust
Aomnitrix2 天前
知识管理新范式——cpolar+Wiki.js打造企业级分布式知识库
开发语言·javascript·分布式
每天回答3个问题2 天前
UE5C++编译遇到MSB3073
开发语言·c++·ue5
伍哥的传说2 天前
Vite Plugin PWA – 零配置构建现代渐进式Web应用
开发语言·前端·javascript·web app·pwa·service worker·workbox
小莞尔2 天前
【51单片机】【protues仿真】 基于51单片机八路抢答器系统
c语言·开发语言·单片机·嵌入式硬件·51单片机
我是菜鸟0713号3 天前
Qt 中 OPC UA 通讯实战
开发语言·qt