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


参考

相关推荐
2301_7634724618 分钟前
C++20概念(Concepts)入门指南
开发语言·c++·算法
TechWJ40 分钟前
PyPTO编程范式深度解读:让NPU开发像写Python一样简单
开发语言·python·cann·pypto
lly2024061 小时前
C++ 文件和流
开发语言
m0_706653231 小时前
分布式系统安全通信
开发语言·c++·算法
寻寻觅觅☆2 小时前
东华OJ-基础题-104-A == B ?(C++)
开发语言·c++
lightqjx2 小时前
【C++】unordered系列的封装
开发语言·c++·stl·unordered系列
zh_xuan2 小时前
kotlin lazy委托异常时执行流程
开发语言·kotlin
阿猿收手吧!2 小时前
【C++】string_view:高效字符串处理指南
开发语言·c++
玄同7653 小时前
我的 Trae Skill 实践|使用 UV 工具一键搭建 Python 项目开发环境
开发语言·人工智能·python·langchain·uv·trae·vibe coding
Yorlen_Zhang3 小时前
Python Tkinter Text 控件完全指南:从基础编辑器到富文本应用
开发语言·python·c#