没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Cargo is the Rust package manager. Cargo downloads your Rust package’s dependencies,compiles your packages, makes distributable packages, and uploads them to crates.io, the Rust community’s package registry. You can contribute to this book on GitHub.
资源推荐
资源详情
资源评论
2020/4/19 The Cargo Book
https://doc.rust-lang.org/stable/cargo/print.html 1/268
The Cargo Book
Cargo is the Rust package manager. Cargo downloads your Rust package’s dependencies,
compiles your packages, makes distributable packages, and uploads them to crates.io, the
Rust community’s package registry. You can contribute to this book on GitHub.
Sections
Getting Started
To get started with Cargo, install Cargo (and Rust) and set up your rst crate.
Cargo Guide
The guide will give you all you need to know about how to use Cargo to develop Rust
packages.
Cargo Reference
The reference covers the details of various areas of Cargo.
Frequently Asked Questions
Appendicies:
Glossary
Git Authentication
Getting Started
To get started with Cargo, install Cargo (and Rust) and set up your rst crate.
2020/4/19 The Cargo Book
https://doc.rust-lang.org/stable/cargo/print.html 2/268
Installation
First steps with Cargo
Installation
Install Rust and Cargo
The easiest way to get Cargo is to install the current stable release of Rust by using rustup .
Installing Rust using rustup will also install cargo .
On Linux and macOS systems, this is done as follows:
It will download a script, and start the installation. If everything goes well, you’ll see this
appear:
On Windows, download and run rustup-init.exe. It will start the installation in a console and
present the above message on success.
After this, you can use the rustup command to also install beta or nightly channels for
Rust and Cargo.
For other installation options and information, visit the install page of the Rust website.
Build and Install Cargo from Source
Alternatively, you can build Cargo from source.
First Steps with Cargo
To start a new package with Cargo, use cargo new :
Cargo defaults to --bin to make a binary program. To make a library, we'd pass --lib .
Let’s check out what Cargo has generated for us:
$ curl https://sh.rustup.rs -sSf | sh
Rust is installed now. Great!
$ cargo new hello_world
2020/4/19 The Cargo Book
https://doc.rust-lang.org/stable/cargo/print.html 3/268
This is all we need to get started. First, let’s check out Cargo.toml :
This is called a manifest, and it contains all of the metadata that Cargo needs to compile
your package.
Here’s what’s in src/main.rs :
Cargo generated a “hello world” for us. Let’s compile it:
And then run it:
We can also use cargo run to compile and then run it, all in one step:
Going further
For more details on using Cargo, check out the Cargo Guide
$ cd hello_world
$ tree .
.
├── Cargo.toml
└── src
└── main.rs
1 directory, 2 files
[package]
name = "hello_world"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]
fn main() {
println!("Hello, world!");
}
$ cargo build
Compiling hello_world v0.1.0 (file:///path/to/package/hello_world)
$ ./target/debug/hello_world
Hello, world!
$ cargo run
Fresh hello_world v0.1.0 (file:///path/to/package/hello_world)
Running `target/hello_world`
Hello, world!
2020/4/19 The Cargo Book
https://doc.rust-lang.org/stable/cargo/print.html 4/268
Cargo Guide
This guide will give you all that you need to know about how to use Cargo to develop Rust
packages.
Why Cargo Exists
Creating a New Package
Working on an Existing Cargo Package
Dependencies
Package Layout
Cargo.toml vs Cargo.lock
Tests
Continuous Integration
Cargo Home
Build Cache
Why Cargo Exists
Cargo is a tool that allows Rust packages to declare their various dependencies and ensure
that you’ll always get a repeatable build.
To accomplish this goal, Cargo does four things:
Introduces two metadata les with various bits of package information.
Fetches and builds your package’s dependencies.
Invokes rustc or another build tool with the correct parameters to build your
package.
Introduces conventions to make working with Rust packages easier.
Creating a New Package
To start a new package with Cargo, use cargo new :
We’re passing --bin because we’re making a binary program: if we were making a library,
we’d pass --lib . This also initializes a new git repository by default. If you don't want it to
do that, pass --vcs none .
Let’s check out what Cargo has generated for us:
$ cargo new hello_world --bin
2020/4/19 The Cargo Book
https://doc.rust-lang.org/stable/cargo/print.html 5/268
Let’s take a closer look at Cargo.toml :
This is called a manifest, and it contains all of the metadata that Cargo needs to compile
your package.
Here’s what’s in src/main.rs :
Cargo generated a “hello world” for us. Let’s compile it:
And then run it:
We can also use cargo run to compile and then run it, all in one step (You won't see the
Compiling line if you have not made any changes since you last compiled):
You’ll now notice a new le, Cargo.lock . It contains information about our dependencies.
Since we don’t have any yet, it’s not very interesting.
Once you’re ready for release, you can use cargo build --release to compile your les
with optimizations turned on:
$ cd hello_world
$ tree .
.
├── Cargo.toml
└── src
└── main.rs
1 directory, 2 files
[package]
name = "hello_world"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]
fn main() {
println!("Hello, world!");
}
$ cargo build
Compiling hello_world v0.1.0 (file:///path/to/package/hello_world)
$ ./target/debug/hello_world
Hello, world!
$ cargo run
Compiling hello_world v0.1.0 (file:///path/to/package/hello_world)
Running `target/debug/hello_world`
Hello, world!
剩余267页未读,继续阅读
资源评论
夏克
- 粉丝: 1w+
- 资源: 19
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于频域处理的图像去网纹方法及其应用
- Windows XP VM虚拟机文件
- Muc数字图像处理-频域处理+复原-去网纹实验代码
- matlab实现扩展卡尔曼滤波器(EKF)三维同步定位与建图(SLAM)及LQR轨迹控制研究-卡尔曼滤波-轨迹控制
- 基于opencv的目标检测 远程手势控制电脑音量项目 源代码 基于opencv实现的手势控制电脑音量项目 通过手部识别出21个关键点,并对21个关键点进行定位和着色,然后做出了个控制电脑音量小项目
- 数字图像处理领域中的甲骨文图符提取技术及其应用:边缘检测、多边形拟合与文字分割
- 双闭环永磁同步电机调速系统(SVPWM) 主电路采用两电平逆变器,永磁同步电机参数已设定,采用空间矢量PWM控制,扇区选择、中间变量、矢量作用时间、切点等模块均搭建完成 控制系统采用双闭环控制系统
- 基于最近电平逼近的开环MMC仿真 DC:12kV,N=12, 采用最近电平逼近调制, 采用基于排序的均压方法,冒泡排序+桥臂电流方向判断 连接负载,可以得到13电平相电压波形 子模块自行搭建,参数
- Muc数字图像处理-甲骨文图符提取代码及图料
- 飞跨电容型NPC逆变器仿真(SPWM) 仿真包含FCNPC拓扑、LCL滤波器、三相纯阻性负载构成主电路 采用SPWM,设计电容平衡模块,构成FCNPC逆变仿真系统 可以得到逆变器输出的三电平相电压
- fluent UDF 中文介绍.zip
- 二极管钳位型NPC逆变并网仿真(SPWM) Matlab 2021a 2016b均可 采用双环PI控制,SPWM,加设LCL滤波器,并网 可以得到逆变器输出为五电平线电压波形,滤波后输出电压,电流均
- 麻雀搜索算法(SSA)文章复现(改进Tent混沌初始化+改进Tent混沌扰动+高斯扰动)-CSSA 复现内容包括:改
- 直流电压源+双向DCDC变器+负载+锂离子电池+控制系统,Simulink仿真模型 有两种工作模式: 1锂离子电池经双向DCDC变器为负载供电 2电压源为负载供电同时经双向DCDC变器为锂离
- 2024年如何提升大模型任务能力报告.pptx
- DataFunSummit非数据中心GPU上的大模型并行训练.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功