当前位置:网站首页>Rust Getting Started Guide (crite Management)
Rust Getting Started Guide (crite Management)
2022-07-28 19:28:00 【Wang Tai】
Rust Getting started (crate management )
This paper is about 「Rust Getting started 」 The second part of the series . This article will focus on cargo cli Tools and Rust Package management system , Include :
This paper mainly introduces cargo Command line and Rust Package management system , Include
Search for crates Used in projects crates To configure crate install / Use cargo-watch
Rust You can refer to the previous article for the basic knowledge of Rust — Getting started (rustup, cargo)
have access to https://geekcode.cloud One click creation of cloud development environment rust The environment quickly starts the following content .
The following content defaults that you have read the content of the previous article , And in https://geekcode.cloud Experienced rustc and rustup.
Crates
crates Namely Rust package . Generated crates Registered in crates.io On the warehouse , We can do it in crates.io Find all crates.
Use cargo The command to search crate. for example , To search and sql dependent crates :
$ cargo search sql
search The result of the command shows the relevant crate Name and version number :

Use Crates
Put what you need crates Add to Cargo.toml In file .
Use $ cargo new {project_name} Created Cargo.toml Content :
[package]
name = "hello_world"
version = "0.1.0"
edition = "2022"# See more keys and their definitions athttps://doc.rust-lang.org/cargo/reference/manifest.html[dependencies]
edit Cargo.toml file , Add the search above sql create:
[package]
name = "hello_world"
version = "0.1.0"
edition = "2018"# See more keys and their definitions athttps://doc.rust-lang.org/cargo/reference/manifest.html[dependencies]
sql = "0.4.3" <-- Add dependency here
Be careful ,Cargo Dependencies and SemVer Syntax is fully compatible , Allow selective updates on demand .
Crates、Git and Feature toggles
Cargo There are powerful functions to obtain crates . You can specify in different ways crate .
Standard way :
[dependencies]
bracket-lib = “~0.8.1”
Appoint Git Warehouse :
[dependencies]
bracket-lib ={ git = "https://github.com/thebracket/bracket-lib" }
Use feature toggles , In the following example , Use bracket-lib , But disable the default rendering engine and use vulkan engine -
[dependencies]
bracket-lib = {
git = "https://github.com/thebracket/bracket-lib",
default-features = false,
features = [ "amethyst_engine_vulkan" ]
}
Source (Source) And binary Crates
C# or NPM The engineer , You will notice that you are adding crate Post run $ cargo build Console output when :
Compiling sql v0.4.3
Compiling hello_world v0.1.0 (/Users/gian/hello_world)
Finished dev [unoptimized + debuginfo] target(s) in 0.99s
majority Rust crate Are based on source code , When adding to a local project ,cargo Will automatically get the source code , Then compile on the platform crate.
If you specify a different target platform ,cargo Will recompile all crate.
Cargo Installation Support binary crates, Specific to crates It's an executable . therefore cargo obtain 、 Compile and then install the generated executable .
To install binary crate, You can use cargo:
$ cargo install {crate_name}
Be careful : Use cargo install Only binary crate. You cannot use this command to install / Add routine crate.
Please see the following cargo-watch An example of .
Cargo-watch
For most crate, You can add them directly to Cargo.toml. use first cargo search Command to find the latest version , Or go directly to crates.io, but You can't Use cargo install.
however , If installed crate yes Binary system crate, Then only use cargo install Can get 、 Compile and install crate For your use .
Be careful : And others crate Different , Install binary crate Only once ( Unless you need to update the binary crate Version of ).
Updating crates.io index
Ignored package `cargo-watch v7.8.1` is already installed, use --force to override
cargo-watch Used to monitor file changes in the project and run commands .
install cargo-watch :
$ cargo install cargo-watch
After installation , Can be accessed immediately cargo-watch Tools :
$ cargo-watch -x build
This command will start a process to monitor the changes of files in the project , under these circumstances , Automatically run when changes are detected cargo build.
You can link multiple commands together like this -
$ cargo-watch -x fmt -x test
If you have installed Rust linter, But it triggers linter, Then run any tests every time the file changes !
You can use cargo-watch Do more , So please check cargo-watch crate file .
summary
Rust crates It is not particularly different from most other packaging systems , But as mentioned above , There are few things to pay attention to .
cargo-watch crate It's binary crate Example , It is also a very convenient utility , When you are in VSCode When you are developing in and want to give immediate feedback on code changes .
There are many other useful crates stay crates.io On .
keep rusty!
Join in GeekCode Community Participation defines Cloud Based IDE

Click on 【 Read the original 】 visit GeekCode
边栏推荐
- RFs self study notes (III): clutter model - first determine the number with Poisson distribution, and then use uniform distribution as probability distribution
- Gmoea code operation 2 -- establishment and operation of operation environment
- 读了三年论文,我今天才学会阅读摘要
- SQL audit tool self introduction owls
- Learn from Li Mu, deep learning - linear regression and basic optimization function
- Application of TSDB in civil aircraft industry
- RTC clock: a calendar
- Prometheus部署
- Asp net MVC web development tutorial
- 图书管理数据库系统设计
猜你喜欢

After several twists and turns, how long can the TSDB C-bit of influxdb last?

Learn from Li Mu in depth -softmax return

英文翻译西班牙语-批量英文翻译西班牙工具免费

Adobe XD web design tutorial

【已解决】AC86U ML改版固件虚拟内存创建失败,提示USB磁盘读写速度不满足要求

用于异常检测的Transformer - InTra《Inpainting Transformer for Anomaly Detection》

Get to know nodejs for the first time (with cases)

When CNN meets transformer cmt:revolutionary neural networks meet vision transformers

英文翻译阿拉伯语-批量英文翻译阿拉伯语工具免费

Gmoea code operation 2 -- establishment and operation of operation environment
随机推荐
sudo rosdep init 出现 ERROR: cannot download default
使用百度EasyDL实现明厨亮灶厨师帽识别
BLDC 6-step commutation simulink
Application of time series database in Hydropower Station
Scrapy Spider源码分析
NDK 系列(5):JNI 从入门到实践,爆肝万字详解!
Application of time series database in intelligent power consumption field
CVPR21-无监督异常检测《CutPaste:Self-Supervised Learning for Anomaly Detection and Localization》
2022年中总结
SaltStack常用的模块
SaltStack之return与job管理
Iclr21 (classification) - future classic "vit" an image is worth 16x16 words (including code analysis)
[radar] radar signal online sorting based on kernel clustering with matlab code
英文翻译西班牙语-批量英文翻译西班牙工具免费
文章翻译软件-批量免费翻译软件支持各大翻译接口
Pandownload revival tutorial
Application of time series database in bridge monitoring field
Nips18 (AD) - unsupervised anomaly detection using geometric transformations using geometric augmentation
剑指 Offer II 109. 开密码锁
机器学习 --- 模型评估、选择与验证