当前位置:网站首页>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
边栏推荐
- 使用SaltStack自动化部署LNMP
- RFs self study notes (4): actual measurement model - the mixture of OK and CK, and then calculate the likelihood probability
- 为什么在telnet登入界面下没有日志输出?
- Method of win7 system anti ARP attack
- How to use Qianqian listening sound effect plug-in (fierce Classic)
- 以数字化转型为契机,3C企业如何通过SRM供应商云协同平台实现高效协同?
- Accumulation and development -- the way of commercialization of open source companies
- 机器学习 --- 模型评估、选择与验证
- IMU heating
- Doxygen文档生成工具
猜你喜欢

当CNN遇见Transformer《CMT:Convolutional Neural Networks Meet Vision Transformers》
![[image hiding] digital image information hiding system based on DCT, DWT, LHA, LSB, including various attacks and performance parameters, with matlab code](/img/a4/5c5a90508e2f9c6b4f8e234bdfdc9e.png)
[image hiding] digital image information hiding system based on DCT, DWT, LHA, LSB, including various attacks and performance parameters, with matlab code

Image processing web application development tutorial

Understanding of PID

Youqilin system installation beyondcomare

RTC clock: a calendar

WPF 实现带蒙版的 MessageBox 消息提示框
![[solved] ac86u ml revision firmware virtual memory creation failed, prompting that the USB disk reading and writing speed does not meet the requirements](/img/1c/6dbfcb5e6ade52d8cbfabcb34616a5.png)
[solved] ac86u ml revision firmware virtual memory creation failed, prompting that the USB disk reading and writing speed does not meet the requirements

SQL audit tool self introduction owls

力扣 1331. 数组序号转换
随机推荐
SQL audit tool self introduction owls
SaltStack之数据系统
Pytorch:快速求得NxN矩阵的主对角线(diagonal)元素与非对角线元素
ardupilot软件在环仿真与在线调试
文章翻译软件-批量免费翻译软件支持各大翻译接口
CVPR19 - 调参干货《Bag of Tricks for Image Classification with Convolutional Neural Network》
TSDB and blockchain
SaltStack进阶
SaltStack常用的模块
Adobe Flash player 34.0.0.92 and available version modification methods (2021-01-23
BLDC 6-step commutation simulink
Iclr21 (classification) - future classic "vit" an image is worth 16x16 words (including code analysis)
使用SaltStack自动化部署LNMP
New functions of ES6 string
Avoidance Adjusted Climbrate
Cvpr21 unsupervised anomaly detection cutpaste:self supervised learning for anomaly detection and localization
SaltStack之salt-ssh
Application of time series database in Hydropower Station
Server body 21: pre compilation processing by different compilers (a brief introduction to MSVC and GCC)
Learn from Li Mu, deep learning - linear regression and basic optimization function