Skip to content

Commit

Permalink
translate intro & 1, 2
Browse files Browse the repository at this point in the history
  • Loading branch information
sunhuachuang committed Aug 21, 2018
1 parent 785f130 commit b0afaf2
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 169 deletions.
2 changes: 1 addition & 1 deletion book.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[book]
authors = ["The Rust Project Developers"]
authors = ["The Rust Project Developers && Sun Huachuang"]
multilingual = false
src = "src"
title = "The Edition Guide"
10 changes: 5 additions & 5 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# The Edition Guide
# 版本指南

[Introduction](introduction.md)
[简介](introduction.md)

## What are editions?
## 什么是版本(Editions)?

- [What are editions?](editions/index.md)
- [Transitioning your code to a new edition](editions/transitioning-your-code-to-a-new-edition.md)
- [什么是版本(Editions)?](editions/index.md)
- [将你的代码迁移到新版本](editions/transitioning-your-code-to-a-new-edition.md)

## Rust 2015

Expand Down
82 changes: 32 additions & 50 deletions src/editions/index.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,32 @@
# What are Editions?

Rust ships releases on a six-week cycle. This means that users get a constant
stream of new features. This is much faster than updates for other languages,
but this also means that each update is smaller. After a while, all of those
tiny changes add up. But, from release to release, it can be hard to look back
and say *"Wow, between Rust 1.10 and Rust 1.20, Rust has changed a lot!"*

Every two or three years, we'll be producing a new *edition* of Rust. Each
edition brings together the features that have landed into a clear package, with
fully updated documentation and tooling. New editions ship through the usual
release process.

This serves different purposes for different people:

- For active Rust users, it brings together incremental changes into an
easy-to-understand package.

- For non-users, it signals that some major advancements have landed, which
might make Rust worth another look.

- For those developing Rust itself, it provides a rallying point for the project as a
whole.

## Compatibility

When a new edition becomes available in the compiler, crates must explicitly opt
in to it to take full advantage. This opt in enables editions to contain
incompatible changes, like adding a new keyword that might conflict with
identifiers in code, or turning warnings into errors. A Rust compiler will
support all editions that existed prior to the compiler's release, and can link
crates of any supported editions together.
Edition changes only affect the way the compiler initially parses the code.
Therefore, if you're using Rust 2015, and
one of your dependencies uses Rust 2018, it all works just fine. The opposite
situation works as well.

Just to be clear: most features will be available on all editions.
People using any edition of Rust will continue to see improvements as new
stable releases are made. In some cases however, mainly when new keywords are
added, but sometimes for other reasons, there may be new features that are only
available in later editions. You only need to upgrade if you want to take
advantage of such features.

## Trying out the 2018 edition

At the time of writing, there are two editions: 2015 and 2018. 2015 is today's
Rust; Rust 2018 will ship later this year. To transition to the 2018 edition
from the 2015 edition, you'll want to get started with the [transition
section](transitioning-your-code-to-a-new-edition.html).
# 什么是版本(Editions)?

Rust 六周发布一次新版本。这意味着用户可以获得不断的新功能。
这比其他语言的更新要快得多,但这也意味着每次更新都会更小。
一段时间之后,所有这些微小的变化都加进来了。
但是,从正式发布到正式发布,很难回头看看 *哇,在 Rust 1.10和 Rust 1.20之间,Rust已经发生了很大变化!*

每隔两三年,我们将制作一个新 *版本* 的 Rust。
每个版本都将功能集成到一个清晰的包中,并提供全面更新的文档和工具。
新版本通过正常的发布流程发布。

这为不同的人提供不同的目的:

- 对于活跃的 Rust 用户,它将增量更改集成到易于理解的包中。

- 对于非用户而言,它表明一些重大进步已经落地,这可能使 Rust 值得再看一眼。

- 对于那些开发 Rust 本身的人来说,它为整个项目提供了一个集结点。

## 兼容性
当编译器中出现新版本时,crates 必须明确选择使用它才能充分利用它。
此选择允许版本包含不兼容的更改,例如添加可能与代码中的标识符冲突的新关键字,或将警告转换为错误。
Rust 编译器将支持编译器发布之前存在的所有版本,并且可以将任何受支持版本的 crates 链接在一起。
版本更改仅影响编译器最初解析代码的方式。
因此,如果您正在使用 Rust 2015,并且您的某个依赖项使用 Rust 2018,那么一切正常。相反的情况也适用。

需要明确的是:大多数功能都适用于所有版本。随着新的稳定版本的发布,使用任何版本的 Rust 的人将继续看到改进。
但是,在某些情况下,主要是在添加新关键字时,但有时由于其他原因,可能会有新功能仅在以后的版本中提供。如果要利用此类功能,则只需升级。

## 试一下2018版本
在撰写本文时,有两个版本:2015和2018。2015是现在的 Rust版本; Rust 2018将于今年晚些时候发布。
要从2015版本过渡到2018版本,您需要开始使用[迁移说明](transitioning-your-code-to-a-new-edition.html)
138 changes: 52 additions & 86 deletions src/editions/transitioning-your-code-to-a-new-edition.md
Original file line number Diff line number Diff line change
@@ -1,99 +1,72 @@
# Transitioning your code to a new edition

New editions might change the way you write Rust -- they add new syntax,
language, and library features but also remove features. For example,
`try`, `async`, and `await` are keywords in Rust 2018, but not Rust 2015.
Despite this it's our intention that the migration to new editions is as
smooth an experience as possible. It's considered a bug if it's difficult to
upgrade your crate to a new edition. If you have a difficult time then a bug
should be filed with Rust itself.

Transitioning between editions is built around compiler lints. Fundamentally,
the process works like this:

* Turn on lints to indicate where code is incompatible with a new edition
* Get your code compiling with no warnings.
* Opt in to the new edition, the code should compile.
* Optionally, enable lints about *idiomatic* code in the new edition.

Luckily, we've been working on Cargo to help assist with this process,
culminating in a new built-in subcommand `cargo fix`. It can take suggestions
from the compiler and automatically re-write your code to comply with new
features and idioms, drastically reducing the number of warnings you need to fix
manually!

> `cargo fix` is still quite young, and very much a work in development. But it
> works for the basics! We're working hard on making it better and more robust,
> but please bear with us for now.
## The preview period

Before an edition is released, it will have a "preview" phase which lets you
try out the new edition in nightly Rust before its release. Currently Rust 2018
is in its preview phase and because of this, there's an extra step you need to
take to opt in. Add this feature flag to your `lib.rs` or `main.rs` as well as
to any examples in the `examples` directory of your project if you have one:
# 迁移你的代码到新版本
新版本可能会改变您编写 Rust 的方式 - 它们会添加新的语法,语言和库功能,但也会删除功能。
例如,`try``async``await`是 Rust 2018 中的关键字,但不在 Rust 2015中。
尽管如此,我们试图尽可能顺利地迁移到新版本。
如果很难将您的 crates 升级到新版本,那么这可能是一个 bug 。如果您遇到困难,那么应该向 Rust 提交一个 bug。

版本之间的迁移是围绕编译器标签(lints)构建的。从根本上说,这个过程是这样的:

* 打开 lints 以指示代码与新版本不兼容的位置
* 在没有警告的情况下编译代码。
* 选择加入新版本,代码应该编译。
*(可选)在新版本中启用有关 *idiomatic* 代码的 lints。

幸运的是,我们一直致力于 Cargo 帮助完成这一过程,最终推出了一个新的内置子命令 `cargo fix`
它可以从编译器中获取建议并自动重新编写代码以符合新功能和习惯用法,从而大大减少手动修复所需的警告数量!

> `cargo fix` 仍然很早期,而且非常重要。但它已经适用于基础部分!我们正在努力使其变得更好,更强大,但暂时不必使用。
## 预览期
在发布版本之前,它将有一个“预览”阶段,让您可以在发布之前在 nightly 的 Rust 中试用新版本。
目前 Rust 2018 正处于预览阶段,因此,您需要采取额外的步骤来选择加入。
将此功能标志添加到您的`lib.rs``main.rs`以及任何示例中。如果你有一个项目的`examples`目录:

```rust
#![feature(rust_2018_preview)]
```

This will enable the unstable features listed in the [feature status][status]
page. Note that some features require a miniumum of Rust 2018 and these features will
require a Cargo.toml change to enable (described in the sections below). Also
note that during the time the preview is available, we may continue to add/enable
new features with this flag!
这将启用 [特性状态][status] 页面中列出的不稳定功能。请注意,某些功能需要最小的 Rust 2018,这些功能需要 Cargo.toml 拥有更改权限才能启用(在下面的部分中描述)。
另请注意,在预览可用期间,我们可能会继续使用此标志来添加/启用新功能!

For Rust 2018 edition preview 2, we're also testing a [new module path
variant](../rust-2018/module-system/path-clarity.html), "uniform paths",
which we'd like to get further testing and feedback on.
Please try it out, by adding the following to your `lib.rs` or `main.rs`:
对于 Rust 2018 预览版2中,我们还测试了[新模块路径变体](../rust-2018/module-system/path-clarity.html),“统一路径”,我们想要获得进一步测试和反馈。
请尝试将以下内容添加到`lib.rs``main.rs`中:

```rust
#![feature(rust_2018_preview, uniform_paths)]
```

The release of Rust 2018 will stabilize one of the two module path variants and
drop the other.
Rust 2018 的发布时候将会选择两个模块路径变体中的一个,并放弃另一个。
The release of Rust 2018 will stabilize one of the two module path variants and drop the other.

[status]: ../unstable-feature-status.html

## Fix edition compatibility warnings
## 修复版本兼容性警告

Next up is to enable compiler warnings about code which is incompatible with the
new 2018 edition. This is where the handy `cargo fix` tool comes into the
picture. To enable the compatibility lints for your project you run:
接下来是启用有关与新 2018 版本 不兼容的代码的编译器警告。 这是方便 `cargo fix` 这个工具进入图片的地方。 要为项目启用兼容性lints,请运行:

```shell
$ cargo fix --edition
```

If the nightly toolchain is not your default, you may need to run this command
instead:
如果 nightly 不是你的默认选择的话,你需要运行下面的这个命令:

```shell
$ cargo +nightly fix --edition
```

This will instruct Cargo to compile all targets in your project (libraries,
binaries, tests, etc.) while enabling all Cargo features and prepare them for
the 2018 edition. Cargo will likely automatically fix a number of files,
informing you as it goes along. Note that this does not enable any new Rust
2018 features; it only makes sure your code is compatible with Rust 2018.
这将指示 Cargo 编译项目中的所有目标(库,二进制文件,测试等),同时启用所有 Cargo 功能并为2018版本做好准备。
Cargo 可能会自动修复一些文件,并在其发生时通知您。 请注意,这不会启用任何新的 Rust 2018 功能; 它只能确保您的代码与 Rust 2018 兼容。

If Cargo can't automatically fix everything it'll print out the remaining
warnings. Continue to run the above command until all warnings have been solved.
如果Cargo无法自动修复所有内容,它将打印出剩余的警告。继续运行上述命令,直到所有警告都已解决。

You can explore more about the `cargo fix` command with:
你可以获取更多 `cargo fix` 信息,运行:

```shell
$ cargo fix --help
```

## Switch to the next edition

Once you're happy with those changes, it's time to use the new edition.
Add this to your `Cargo.toml`:
## 切换到下一个版本
一旦您对这些更改感到满意,就可以使用新版本了。 将其添加到您的 `Cargo.toml`

```toml
cargo-features = ["edition"]
Expand All @@ -102,42 +75,35 @@ cargo-features = ["edition"]
edition = '2018'
```

That `cargo-features` line should go at the very top; and `edition` goes into
the `[package]` section. As mentioned above, right now this is a nightly-only
feature of Cargo, so you need to enable it for things to work.
那个 `cargo-features` 行应该排在最前面; `edition` 进入 `[package]` 部分。
如上所述,现在这是 Cargo 的 nightly 特征,因此您需要启用它才能使其工作。

At this point, your project should compile with a regular old `cargo
build`. If it does not, this is a bug! Please [file an issue][issue].
此时,您的项目应该使用常规的`cargo build`进行编译。 如果没有,这是一个错误! 请[提交问题][issue]

[issue]: https://github.com/rust-lang/rust/issues/new

## Writing idiomatic code in a new edition
## 在新版本中编写惯用代码
你的 crate 现在已经进入了2018版的 Rust,恭喜! 回想一下,Rust 中的 Editions 表示随着时间的推移,习惯用语的转变。
虽然很多旧代码将继续编译,但今天可能会用不同的习惯用语编写。

Your crate has now entered the 2018 edition of Rust, congrats! Recall though
that Editions in Rust signify a shift in idioms over time. While much old
code will continue to compile it might be written with different idioms today.

An optional next step you can take is to update your code to be idiomatic within
the new edition. This is done with a different set of "idiom lints". Like before
we'll be using `cargo fix` to drive this process:
您可以采取的可选的后续步骤是将代码更新为新版本中的惯用语。
这是通过一组不同的“习惯用语lints”完成的。 就像之前我们使用 `cargo fix` 来推动这个过程一样:

```shell
$ cargo fix --edition-idioms
```

Additionally like before, this is intended to be an *easy* step. Here `cargo
fix` will automatically fix any lints it can, so you'll only get warnings for
things that `cargo fix` couldn't fix. If you find it difficult to work through
the warnings, that's a bug!
与之前一样,这是一个 *简单* 的步骤。
在这里 `cargo fix` 将自动修复任何可能的lint,所以你只会得到 `cargo fix` 无法修复的情况下的警告。
如果您发现难以完成警告,那就是一个错误!

一旦你用这个命令警告没有了,你就可以继续了。

Once you're warning-free with this command you're good to go.

> The `--edition-idioms` flag applies only to the "current crate" if you want
> to run it against a workspace is necessary to use a workaround with
> `RUSTFLAGS` in order to execute it in all the workspace members.
> `--edition-idioms` 标志仅适用于“当前 crate”,如果你想在工作空间运行它是必要的,使用 `RUSTFLAGS` 的解决方法,以便在所有工作区中执行它。
>
> ```shell
> $ RUSTFLAGS='-Wrust_2018_idioms' cargo fix --all
> ```
Enjoy the new edition!
享受新版本吧!
22 changes: 9 additions & 13 deletions src/introduction.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
# Introduction
# 简介

Welcome to the Rust Edition Guide! "Editions" are Rust's way of communicating
large changes in the way that it feels to write Rust code.
欢迎来到 Rust 版本(Edition)使用指南! "Editions" 是通过编写 Rust 代码来传达巨大改变的一种方式。

In this guide, we'll discuss:
在指南中,我们将讨论:
* 什么是版本(editions)
* 每个版本什么样
* 如何将你的代码从一个版本迁移到另一个版本

* What editions are
* What each edition is about
* How to migrate your code from one edition to another

Note that the standard library grows with each Rust release; there are *many*
additions to the standard library that are not called out in this guide. Only
the major ones are, but there's tons of medium and small things that are
great too. You may want to check out [the standard library
documentation](https://doc.rust-lang.org/std/) as well.
请注意,标准库随每个Rust版本的增长而增长; 标准库中有*许多*添加的内容,本指南未对其进行说明。
只包含那些主要的变化,当然同时也有大量的中小型的改变也很棒。
您可能还想查看[标准库文档](https://doc.rust-lang.org/std/)
19 changes: 5 additions & 14 deletions src/rust-2015/index.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
# Rust 2015

Rust 2015 has a theme of "stability". It commenced with the release of 1.0,
and is the "default edition". The edition system was conceived in late 2017,
but Rust 1.0 was released in May of 2015. As such, 2015 is the edition
that you get when you don't specify any particular edition, for backwards
compatibility reasons.
Rust 2015 的主题是“稳定性”。 它从1.0版本开始,是“默认版”。
该版本系统于2017年底构思,但 Rust 1.0 于2015年5月发布。因此,2015年是您未指定任何特定版本时获得的版本,出于向后兼容性原因。

"Stability" is the theme of Rust 2015 because 1.0 marked a huge change in
Rust development. Previous to Rust 1.0, Rust was changing on a daily basis.
This made it very difficult to write large software in Rust, and made it
difficult to learn. With the release of Rust 1.0 and Rust 2015, we committed
to backwards compatibility, ensuring a solid foundation for people to build
projects on top of.
“稳定性”是 Rust 2015 的主题,因为1.0标志着 Rust 开发的巨大变化。 在 Rust 1.0 之前,Rust 每天都在变化。 这使得在 Rust 中编写大型软件变得非常困难,并且难以学习。
随着 Rust 1.0 和 Rust 2015 的发布,我们致力于向后兼容,确保为人们构建项目奠定坚实的基础。

Since it's the default edition, there's no way to port your code to Rust
2015; it just *is*. You'll be transitioning *away* from 2015, but never
really *to* 2015. As such, there's not much else to say about it!
由于它是默认版本,因此无法将代码移植到 Rust 2015; 它 *就是*。 你将从 2015 开始 *过渡*,但从未真正 ** 2015版。因此,没有什么可说的了!

0 comments on commit b0afaf2

Please sign in to comment.