Merge pull request #4558 from OneNewLife/master

[Translated by OneNewLife]20160921 Rust meets Fedora.md
This commit is contained in:
Xingyu.Wang 2016-10-18 18:33:49 +08:00 committed by GitHub
commit 9eee0cb8d4
2 changed files with 71 additions and 71 deletions

View File

@ -1,71 +0,0 @@
OneNewLife translating
### [Rust meets Fedora](https://fedoramagazine.org/rust-meets-fedora/)
### ![rust](https://i2.wp.com/cdn.fedoramagazine.org/wp-content/uploads/2016/09/rust.jpg?fit=945%2C400&ssl=1)
### What is Rust?
Rust is a system programming language which runs blazingly fast, and prevents almost all crashes, [segfaults](https://wikipedia.org/wiki/Segmentation_fault), and data races. You might wonder exactly why yet another programming language is useful, since there are already so many of them. This article aims to explain why.
### Safety vs. control
[![Why Rust?](https://i0.wp.com/cdn.fedoramagazine.org/wp-content/uploads/2016/09/Screenshot-from-2016-09-12-08-29-02.png?resize=300%2C210&ssl=1)](https://i0.wp.com/cdn.fedoramagazine.org/wp-content/uploads/2016/09/Screenshot-from-2016-09-12-08-29-02.png?ssl=1)
You may have seen a diagram of the above spectrum. On one side theres C/C++, which has more control of the hardware its running on. Therefore it lets the developer optimize performance by executing finer control over the generated machine code. However, this isnt very safe; its easier to cause a segfault, or security bugs like [Heartbleed](https://fedoramagazine.org/update-on-cve-2014-0160-aka-heartbleed/).
On the other hand, there are languages like Python, Ruby, and JavaScript where the developer has little control but creates safer code. The code cant generate a segfault, although it can generate exceptions which are fairly safe and contained.
Somewhere in the middle, theres Java and a few other languages which are a mixture of these characteristics. They offer some control of the hardware they run on but try to minimize vulnerabilities.
Rust is a bit different, and doesnt fall in this spectrum. Instead it gives the developer both safety and control.
### Specialties of Rust
Rust is a system programming language like C/C++, except that it gives the developer fine grained control over memory allocations. A garbage collector is not required. It has a minimal runtime, and runs very close to the bare metal. The developer has greater guarantees about the performance of the code. Furthermore, anyone who knows C/C++ can understand and write code for this language.
Rust runs blazingly fast, since its a compiled language. It uses LLVM as the compiler backend and can tap into a large suite of optimizations. In many areas it can perform better than C/C++. Like JavaScript, Ruby, and Python, its safe by default, meaning it doesnt cause segfaults, dangling pointers, or null pointers.
Another important feature is the elimination of data races. Nowadays, most computers have multiple cores and many threads running in parallel. However its tough for developers to write good parallel code, so this feature removes that necessity. There are two key concepts Rust uses to eliminate data races:
* Ownership. Each variable is moved to a new location, and prevents the previous location from using it. There is only oneowner of each piece of data.
* Borrowing. Owned values can be borrowed to allow usage for a certain period of time.
### Rust in Fedora 24 and 25
To get started, just install the package:
```
sudo dnf install rust
```
```
fn main() {
println!("Hello, Rust is running on Fedora 25 Alpha!");
}
```
```
rustc helloworld.rs
./helloworld
```
Run the following command to install the latest testing version on Fedora:
```
sudo dnf --enablerepo=updates-testing --refresh --best install rust
```
--------------------------------------------------------------------------------
via: https://fedoramagazine.org/rust-meets-fedora/
作者:[Sumantro Mukherjee][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://fedoramagazine.org/author/sumantrom/

View File

@ -0,0 +1,71 @@
OneNewLife translated
### [Rust 遇上 Fedora](https://fedoramagazine.org/rust-meets-fedora/)
### ![rust](https://i2.wp.com/cdn.fedoramagazine.org/wp-content/uploads/2016/09/rust.jpg?fit=945%2C400&ssl=1)
### Rust 是什么?
Rust 是一种系统编程语言,它运行速度惊人,并且可以避免几乎所有的崩溃、[内存区块错误](https://wikipedia.org/wiki/Segmentation_fault) 以及数据竞争。你也许会质疑为什么它是有用的,因为已经有很多同类的语言了。这篇文章将会告诉你为什么。
### 安全性 vs. 控制权
[![为什么选择 Rust](https://i0.wp.com/cdn.fedoramagazine.org/wp-content/uploads/2016/09/Screenshot-from-2016-09-12-08-29-02.png?resize=300%2C210&ssl=1)](https://i0.wp.com/cdn.fedoramagazine.org/wp-content/uploads/2016/09/Screenshot-from-2016-09-12-08-29-02.png?ssl=1)
你应该看到了上面的图谱。一边是 C/C++,对运行的硬件拥有更多的控制权,因此它可以让开发者通过对所生成的机器代码进行更精细的控制来优化性能。然而这不是很安全,这很容易造成内存区块错误以及像 [Heartbleed](https://fedoramagazine.org/update-on-cve-2014-0160-aka-heartbleed/) 这样的安全漏洞。
另一边是像 Python、Ruby 和 JavaScript 这种没有给予开发者多少控制权但是可以创建出更安全的代码的语言。虽然这些代码可以生成相当安全并且可控的异常,但是它们不会造成内存区块错误。
在图谱中间的区域是 Java 和其它混合了这些特性的语言。它们提供对运行的硬件部分控制权,并且尝试最小化漏洞。
Rust 有点不太一样,它并没有出现在这个图谱上。它同时提供给开发者安全性和控制权。
### Rust 的特性
Rust 是一种像 C/C++ 一样的系统编程语言,除此之外它还给予开发者对内存分配细粒度的控制。它不需要垃圾回收器。它的运行时间很短,接近于裸机的运行时间。它为开发者提供了代码性能更大的保证。此外,任何知道 C/C++ 的人都能读懂以及编写 Rust 的代码。
Rust 的运行速度非常快,因为它是一种编译语言。它使用 LLVM 作为编译器的后端,并且还可以利用一大堆优化。在许多领域,它的性能都要高于 C/C++。而 JavaScript、Ruby 和 Python 与生俱来就是安全的,这意味着它们不会造成内存区块错误、野指针或者空指针。
另外一个很重要的特性就是消除数据竞争。如今大多数计算机都具有多个核心和多个并行运行的线程。然而开发者很难编写好的并行代码因此这个特性除去了他们的后顾之忧。Rust 使用两个关键概念来消除数据竞争:
* 所有权。每一个变量都被移动到一个新的位置,并防止通过先前的位置来引用它。每一个数据块只有一个所有者。
* 借用。可以借用拥有的值以允许在一段时间内使用。
### 在 Fedora 24 和 25 上使用 Rust
若要开始使用,只需安装软件包:
```
sudo dnf install rust
```
```
fn main() {
println!("Hello, Rust is running on Fedora 25 Alpha!");
}
```
```
rustc helloworld.rs
./helloworld
```
在 Fedora 上执行以下命令来安装最新的测试版本:
```
sudo dnf --enablerepo=updates-testing --refresh --best install rust
```
--------------------------------------------------------------------------------
编译自: https://fedoramagazine.org/rust-meets-fedora/
作者:[Sumantro Mukherjee][a]
译者:[OneNewLife](https://github.com/OneNewLife)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://fedoramagazine.org/author/sumantrom/