-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
02c835a
commit 9c6b6a0
Showing
10 changed files
with
87 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 25 additions & 38 deletions
63
src/rust-2018/cargo-and-crates-io/cargo-check-for-faster-checking.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,41 @@ | ||
# `cargo check` for faster checking | ||
# `cargo check` 用于快速检查 | ||
|
||
![Minimum Rust version: 1.16](https://img.shields.io/badge/Minimum%20Rust%20Version-1.16-brightgreen.svg) | ||
|
||
`cargo check` is a new subcommand should speed up the development | ||
workflow in many cases. | ||
|
||
What does it do? Let's take a step back and talk about how `rustc` compiles | ||
your code. Compilation has many "passes", that is, there are many distinct | ||
steps that the compiler takes on the road from your source code to producing | ||
the final binary. However, you can think of this process in two big steps: | ||
first, `rustc` does all of its safety checks, makes sure your syntax is | ||
correct, all that stuff. Second, once it's satisfied that everything is in | ||
order, it produces the actual binary code that you end up executing. | ||
|
||
It turns out that that second step takes a lot of time. And most of the time, | ||
it's not neccesary. That is, when you're working on some Rust code, many | ||
developers will get into a workflow like this: | ||
|
||
1. Write some code. | ||
2. Run `cargo build` to make sure it compiles. | ||
3. Repeat 1-2 as needed. | ||
4. Run `cargo test` to make sure your tests pass. | ||
5. Try the binary yourself | ||
6. GOTO 1. | ||
|
||
In step two, you never actually run your code. You're looking for feedback | ||
from the compiler, not to actually run the binary. `cargo check` supports | ||
exactly this use-case: it runs all of the compiler's checks, but doesn't | ||
produce the final binary. To use it: | ||
`cargo check` 是一个新的子命令,可以在很多情况下加快开发工作流程。 | ||
|
||
它有什么作用?让我们退一步说,讨论 `rustc` 如何编译代码。编译有许多“过程”,也就是说,编译器在从源代码到生成最终二进制文件的过程中有许多不同的步骤。 | ||
但是,您可以通过两个重要步骤来考虑这个过程:首先,`rustc` 执行所有安全检查,确保您的语法正确,所有这些。其次,一旦满足一切顺序,就会生成最终执行的实际二进制代码。 | ||
|
||
事实证明,第二步需要花费很多时间。而且大多数时候,这不是必要的。也就是说,当您处理一些 Rust 代码时,许多开发人员将进入这样的工作流程: | ||
|
||
1. 写一些代码。 | ||
2. 运行 `cargo build` 以确保它编译。 | ||
3. 根据需要重复1-2。 | ||
4. 运行 `cargo test` 以确保测试通过。 | ||
5. 亲自尝试二进制文件 | ||
6. GOTO 1。 | ||
|
||
在第二步中,您实际上从未运行过您的代码。您正在寻找编译器的反馈,而不是实际运行二进制文件。 `cargo check` 正好支持这个用例:它运行所有编译器的检查,但不生成最终的二进制文件。要使用它: | ||
|
||
```console | ||
$ cargo check | ||
``` | ||
|
||
where you may normally `cargo build`. The workflow now looks like: | ||
|
||
1. Write some code. | ||
2. Run `cargo check` to make sure it compiles. | ||
3. Repeat 1-2 as needed. | ||
4. Run `cargo test` to make sure your tests pass. | ||
5. Run `cargo build` to build a binary and try it yourself | ||
6. GOTO 1. | ||
在那里你通常可以 `cargo build`。 工作流现在看起来像: | ||
|
||
1. 写一些代码。 | ||
2. 运行`cargo check`以确保它编译。 | ||
3. 根据需要重复1-2。 | ||
4. 运行`cargo test`以确保测试通过。 | ||
5. 运行`cargo build`来构建二进制文件并自己尝试 | ||
6. GOTO 1。 | ||
|
||
So how much speedup do you actually get? Like most performance related | ||
questions, the answer is "it depends." Here are some very un-scientific | ||
benchmarks at the time of writing. | ||
那么你实际获得了多少加速?与大多数相关的问题一样,答案是“它取决于”。在撰写本文时,这里有一些非科学的基准。 | ||
|
||
| build | performance | check performance | speedup | | ||
|--------|-------------|-------------------|---------| | ||
| initial compile | 11s | 5.6s | 1.96x | | ||
| second compile (no changes) | 3s | 1.9s | 1.57x | | ||
| third compile with small change | 5.8s | 3s | 1.93x | | ||
| third compile with small change | 5.8s | 3s | 1.93x | |
20 changes: 8 additions & 12 deletions
20
src/rust-2018/cargo-and-crates-io/cargo-install-for-easy-installation-of-tools.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,30 @@ | ||
# `cargo install` for easy installation of tools | ||
# `cargo install` 用于自动安装 | ||
|
||
![Minimum Rust version: 1.5](https://img.shields.io/badge/Minimum%20Rust%20Version-1.5-brightgreen.svg) | ||
|
||
Cargo has grown a new `install` command. This is intended to be used for installing | ||
new subcommands for Cargo, or tools for Rust developers. This doesn't replace the need | ||
to build real, native packages for end-users on the platforms you support. | ||
Cargo 已经发展了一种新的 `install` 命令。 这旨在用于为 Cargo 安装新的子命令,或者为 Rust 开发人员安装工具。 | ||
这并不能取代为您支持的平台上的最终用户构建真实的本机程序包的需要。 | ||
|
||
For example, this guide is created with [`mdbook`](https://crates.io/crates/mdbook). You | ||
can install it on your system with | ||
例如,本指南是使用 [`mdbook`](https://crates.io/crates/mdbook)。 你可以将它安装在你的系统上: | ||
|
||
```console | ||
$ cargo install mdbook | ||
``` | ||
|
||
And then use it with | ||
然后使用: | ||
|
||
```console | ||
$ mdbook --help | ||
``` | ||
|
||
As an example of extending Cargo, you can use the [`cargo-update`](https://crates.io/crates/cargo-update) | ||
package. To install it: | ||
作为扩展 Cargo 的示例,你可以使用[`cargo-update`](https://crates.io/crates/cargo-update)包。 要安装它: | ||
|
||
```console | ||
$ cargo install cargo-update | ||
``` | ||
|
||
This will allow you to use this command, which checks everything you've `cargo install`'d and | ||
updates it to the latest version: | ||
这将允许你使用此命令,该命令检查你 `cargo install` 的所有内容并将其更新为最新版本: | ||
|
||
```console | ||
$ cargo install-update -a | ||
``` | ||
``` |
20 changes: 6 additions & 14 deletions
20
src/rust-2018/cargo-and-crates-io/cargo-new-defaults-to-a-binary-project.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,10 @@ | ||
# `cargo new` defaults to a binary project | ||
# `cargo new` 创建一个默认可执行项目 | ||
|
||
![Minimum Rust version: 1.25](https://img.shields.io/badge/Minimum%20Rust%20Version-1.25-brightgreen.svg) | ||
|
||
`cargo new` will now default to generating a binary, rather than a library. | ||
We try to keep Cargo’s CLI quite stable, but this change is important, and is | ||
unlikely to cause breakage. | ||
`cargo new` 现在默认生成二进制文件,而不是库。我们试图保持 Cargo 的 CLI 非常稳定,但这种变化很重要,不太可能导致破损。 | ||
|
||
For some background, cargo new accepts two flags: `--lib`, for creating | ||
libraries, and `--bin`, for creating binaries, or executables. If you don’t | ||
pass one of these flags, it used to default to `--lib`. At the time, we made | ||
this decision because each binary (often) depends on many libraries, and so | ||
we thought the library case would be more common. However, this is incorrect; | ||
each library is depended upon by many binaries. Furthermore, when getting | ||
started, what you often want is a program you can run and play around with. | ||
It’s not just new Rustaceans though; even very long-time community members | ||
have said that they find this default surprising. As such, we’ve changed it, | ||
and it now defaults to `--bin`. | ||
对于某些背景,cargo new 接受两个标志: `--lib` 用于创建库,`--bin` 用于创建二进制文件或可执行文件。 如果你没有传递其中一个标志,它曾经默认为 `--lib`。 | ||
当时,我们做出了这个决定,因为每个二进制文件(通常)都依赖于许多库,因此我们认为库案例会更常见。但是,这是不正确的; 每个包都依赖于许多二进制文件。 | ||
此外,在开始使用时,你经常需要的是一个可以运行和使用的程序。而且,不仅仅是新 Rustaceans们, 甚至是很长时间的社区成员都说他们发现这个默认值令人惊讶。 | ||
因此,我们已经改变它,它现在默认为 `--bin`。 |
18 changes: 7 additions & 11 deletions
18
...st-2018/cargo-and-crates-io/cargo-rustc-for-passing-arbitrary-flags-to-rustc.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,17 @@ | ||
# `cargo rustc` for passing arbitrary flags to rustc | ||
# `cargo rustc` 用于传递标记至 rustc | ||
|
||
![Minimum Rust version: 1.1](https://img.shields.io/badge/Minimum%20Rust%20Version-1.1-brightgreen.svg) | ||
|
||
`cargo rustc` is a new subcommand for Cargo that allows you to pass arbitrary | ||
`rustc` flags through Cargo. | ||
`cargo rustc` 是Cargo的一个新的子命令,它允许你通过 cargo 传递任意标记到 `rustc`。 | ||
|
||
For example, Cargo does not have a way to pass unstable flags built-in. But | ||
if we'd like to use `print-type-sizes` to see what layout information our | ||
types have. We can run this: | ||
例如,Cargo 没有办法传递内置的不稳定标志。但是如果我们想使用 `print-type-sizes` 来查看我们的类型有哪些布局信息。我们可以运行这个: | ||
|
||
```console | ||
$ cargo rustc -- -Z print-type-sizes | ||
``` | ||
|
||
And we'll get a bunch of output describing the size of our types. | ||
我们将得到一堆描述我们类型大小的输出。 | ||
|
||
## Note | ||
|
||
`cargo rustc` only passes these flags to invocations of your crate, and not to any `rustc` | ||
invocations used to build dependencies. If you'd like to do that, see `$RUSTFLAGS`. | ||
## 注意 | ||
`cargo rustc` 只会将这些标记传递给你的 crate 的调用,而不是用于构建依赖项的任何 `rustc` 调用。 | ||
如果你想这样做,请参阅 `$RUSTFLAGS`。 |
27 changes: 12 additions & 15 deletions
27
src/rust-2018/cargo-and-crates-io/cargo-workspaces-for-multi-package-projects.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,27 @@ | ||
# Cargo workspaces for multi-package projects | ||
# Cargo workspaces 用于有多个子包的项目 | ||
|
||
![Minimum Rust version: 1.12](https://img.shields.io/badge/Minimum%20Rust%20Version-1.12-brightgreen.svg) | ||
|
||
Cargo used to have two levels of organization: | ||
Cargo 曾经有两个组织层次: | ||
|
||
* A *package* contains one or more crates | ||
* A crate has one or more modules | ||
* 一个 *package* 有一个或多个 crates | ||
* 一个 *crate* 有一个或多个 modules | ||
|
||
Cargo now has an additional level: | ||
Cargo 现在有一个额外的层次: | ||
|
||
* A *workspace* contains one or more packages | ||
* 一个 *workspace* 包含一个或多个 packages | ||
|
||
This can be useful for larger projects. For example, [the `futures` | ||
respository] is a *workspace* that contains many related packages: | ||
[the `futures` package]: https://github.com/rust-lang-nursery/futures-rs | ||
|
||
这对于大型项目非常有用。例如,[the `futures` package] 是一个 *workspace*,包含许多相关的包: | ||
|
||
* futures | ||
* futures-util | ||
* futures-io | ||
* futures-channel | ||
|
||
and more. | ||
|
||
[the `futures` package]: https://github.com/rust-lang-nursery/futures-rs | ||
还有其他。 | ||
|
||
Workspaces allow these packages to be developed individually, but they share | ||
a single set of dependencies, and therefore have a single target directory | ||
and a single `Cargo.lock`. | ||
Workspaces 允许单独开发这些包,但它们共享一组依赖项,因此只有单个 target 目录和单个 `Cargo.lock`。 | ||
|
||
For more details about workspaces, please see [the Cargo documentation](https://doc.rust-lang.org/stable/cargo/reference/manifest.html#the-workspace-section). | ||
更多有关 workspaces, 请查阅 [the Cargo documentation](https://doc.rust-lang.org/stable/cargo/reference/manifest.html#the-workspace-section). |
14 changes: 5 additions & 9 deletions
14
src/rust-2018/cargo-and-crates-io/crates-io-disallows-wildcard-dependencies.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,21 @@ | ||
# Crates.io disallows wildcard dependencies | ||
# Crates.io 不允许使用通配符 | ||
|
||
![Minimum Rust version: 1.6](https://img.shields.io/badge/Minimum%20Rust%20Version-1.6-brightgreen.svg) | ||
|
||
Crates.io will not allow you to upload a package with a wildcard dependency. | ||
In other words, these: | ||
Crates.io 不允许您上传具有通配符依赖关系的包。 换句话说,这些: | ||
|
||
```toml | ||
[dependencies] | ||
regex = "*" | ||
``` | ||
|
||
A wildcard dependency means that you work with any possible version of your | ||
dependency. This is highly unlikely to be true, and would cause unnecessary | ||
breakage in the ecosystem. | ||
通配符依赖性意味着您可以使用任何可能的依赖项版本。 这极不可能是真实的,并且会在生态系统中造成不必要的破坏。 | ||
|
||
Instead, depend on a version range. For example, `^` is the default, so | ||
you could use | ||
相反,取决于版本范围。例如,`^`是默认值,因此您可以使用: | ||
|
||
```toml | ||
[dependencies] | ||
regex = "1.0.0" | ||
``` | ||
|
||
instead. `>`, `<=`, and all of the other, non-`*` ranges work as well. | ||
相应的, `>`, `<=`, 和所有其他的非`*`范围都是可以的。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters