The Issue Of Rust 1.21
the Rust Team is pleased to present the release of Rust 1.21.0. Rust is a systems programming language aimed at speed, security, and parallel code execution.
If you have a previous version of Rust, to update it enough to run:
the
$ rustup stable update
If you have not installed rustup
, you can install it to the appropriate pages of our web site. With detailed release notes Rust 1.21.0 can be found on GitHub.
What's included in the stable version 1.21.0
This release contains several small but useful changes to the language and new documentation.
the First change is in literals. Consider this code:
the
let x = &5;
In Rust it is similar to the following:
the
let _x = 5;
let x = &_x;
That is 5
will be put on the stack in registers, and x
will be a link to it.
However, given that we are talking about an integer literal, there is no reason to make the value of this local. Imagine that we have a function that accepts 'static
argument, like std::thread::spawn
. Then you could use x
:
the
use std::thread;
fn main() {
let x = &5;
thread::spawn(move || {
println!("{}", x);
});
}
This code is not going to past versions, and Rust':
the
error[E0597]: borrowed value does not live long enough
--> src/main.rs:4:14
|
4 | let x = &5;
| ^ does not live long enough
...
10 | }
| - temporary value only lives until here
|
= note: borrowed value must be valid for the static lifetime...
because of the locality of the 5
, a link to it, too, lives too small to meet the requirements of the spawn
.
But if you build it with Rust 1.21, it's working. Why? If something that created a link can be put into static
, we could "obeschaet" let x = &5;
to something like:
the
static FIVE: i32 = 5;
let x = &FIVE;
once FIVE
is static
, x
is &'static i32
. So Rust now and will work in such cases. For details, see RFC 1414, which was adopted in January 2017, but beginning in December 2015!
Now we run LLVM in parallel with code generation, which should reduce peak memory consumption.
RLS can now be installed through rustup a call to rls rustup add component-preview
. A lot of useful tools such as RLS, Clippy and rustfmt
, still require night Rust, but this is the first step to their work on stable channel. Expect further improvements in the future, but for now take a look at a preliminary version.
Now about the improvements of the documentation. First: if you look at documentation for the module std::os
that contains the functionality of working with operating systems, you will see not only the Linux
— the platform on which the documentation was collected. We have long been upset that the official documentation was Linux only. This is the first step to remedy the situation,
although so far it is available only standard library, not for any package (crate). We hope to fix this in the future.
Next, Cargo documentation has moved! Historically, the documentation of the Cargo was placed on doc.crates.io that should not have model releases (release train model), although the Cargo followed. This led to situations where some functionality soon had to join in night Cargo, documentation was updated, and for the next 12 weeks users thought that everything works, although this has not been true. https://doc.rust-lang.org/cargo will be the new home for documentation of Cargo, but now this address just redirects to the doc.crates.io. Future releases will move the available documentation Cargo, and then doc.crates.io will be redirected to doc.rust-lang.org/cargo. Documentation Cargo has long been in need of updating, so expect more news about it soon!
for Details, see release notes.
Stabilization in the standard library
In this release, not so many stabilizations, but there's something very simplifying life: due to the lack of generalizations about integers (type-level integers), arrays of supported types only up to size 32. Now this is patched for Clone type
. By the way, it's caused a lot of ICE (internal compiler error) when the type is implemented only Copy
but not Clone
.
For other types, recently, was adopted by the RFC on the generalization of relative integers, which should correct the situation. This change is not yet implemented, but preparations are already underway.
Then was stable Iterator::for_each
, giving the opportunity to absorb the iterator for side effects without for
loop:
the
// old way
for i in 0..10 {
println!("{}", i);
}
// new method
(0..10).for_each(|i| println!("{}", i));
Which way is better depends on the situation. In the above code, for
loop is simple, but if you build a chain of iterators, the version with for_each
may be clearer:
the
// old way
for i in (0..100).map(|x| x + 1).filter(|x| x % 2 == 0) {
println!("{}", i);
}
// new method
(0..100)
.map(|x| x + 1)
.filter(|x| x % 2 == 0)
.for_each(|i| println!("{}", i));
a Stable max
and min
of type Ord
.
a Stable inline function (intrinsic) needs_drop
.
Finally, stabilized std::mem::discriminant
, allowing you to see the active version of the transfer without using match
operator.
for Details, see release notes.
Cargo Functionality
in Addition to the above documentation change Cargo in this edition receives a big update: [patch]
. Developed in RFC 1969, section [patch]
in your Cargo.toml
can be used when you want to replace part of your dependency graph. It could have been done before, via the [relace]
. In short, [patch]
is a new and more convenient [replace]
. Although we have no plans to remove or declare obsolete [replace]
, you should most probably use [patch]
.
How does [patch]
? Let's say we have this Cargo.toml
:
the
[dependencies]
foo = "1.2.3"
as our package (crate) foo
depends on package bar
, and we have found a bug in bar
. To test this, we downloaded the source code of bar
and update our Cargo.toml
:
the
[dependencies]
foo = "1.2.3"
[patch.crates-io]
bar = { path = '/path/to/bar' }
Now when you run the cargo build
will be used by our local version of bar
and not the version of crates.io
, which actually depends on the foo
.
for Details, see documentation.
Also:
the
-
the
you can Now use cargo install
to allow simultaneous installation of several packages.
the Argument --all
is automatically added to the team if you are working in a virtual space (virtual workspace).
the include Fields
andexclude
in yourCargo.toml
now accept the templates are the same.gitignore
.
for Details, see release notes.
Many people were involved in the development of Rust 1.21. We would not be able to achieve this without each of you. Thank you!
From the interpreter: Thank you, sasha_gav and vitvakatu for help in translation
Комментарии
Отправить комментарий