The Rust team is pleased to present the release of Rust 1.18.0. Rust is a system programming language aimed at security, speed, and parallel code execution.
If you have a previous version of Rust installed, then it’s enough to upgrade:
$ rustup update stable
If you have not yet installed Rust, you can rustup
from the corresponding page of our website and read the detailed release notes for 1.18.0 on GitHub.
As always, Rust 1.18.0 gathered a lot of improvements and new features.
One of the largest and most anticipated changes: members of the team Carol Nichols and Steve Klabnik write a new edition of the Rust Programming Language, the official book about Rust. It is written openly on GitHub , and more than a hundred people have already contributed to it. This release includes the first draft of the second edition in our online documentation . 19 of the 20 chapters have already been written, a draft of chapter 20 will be added in the Rust 1.19 release. When the book is completed, a print version will be available through No Starch Press , if you prefer a paper copy. We are still working with the editors of No Startch to improve the text, but we would like to present the book to a wide audience now.
The new edition is written completely from scratch, using the knowledge gained by us in the last two years of training people Rust. You will find completely new explanations of many key concepts of Rust, new projects for learning, and many other interesting and useful things. Please take a look and tell us what you think !
As for the language itself, the old features gained new features: the pub
keyword was expanded a bit. Experienced Rust programmers know that in Rust, all elements are private by default, and you must use the pub
keyword to make them public. In Rust 1.18.0 pub
got a new form :
pub(crate) bar;
The expression inside ()
is a 'constraint' that specifies the scope. Using the crate
keyword in the example above means that bar
will be public for the entire container (crate), but not outside of it. This makes it easy to create APIs that are "public to your container" but not accessible to your users. This was possible with the existing system of modules, but very often it looked inconvenient.
You can also specify a path, for example:
pub(in a::b::c) foo;
This means " foo
publicly inside the a::b::c
hierarchy, but nowhere else." This feature was defined in RFC 1422 and described in the documentation .
For Windows users, Rust 1.18.0 has a , #![windows_subsystem]
. It works like this:
#![windows_subsystem = "console"] #![windows_subsystem = "windows"]
These expressions control the linker /SUBSYSTEM
. Currently, only console
and windows
.
When can this be useful? In the simplest case, if you are developing a graphical application, and did not specify windows
, the console window will appear when your application starts. With this flag, this will not happen.
Finally, tuples, enumerations, and structures (without #[repr]
) always had indefinite memory allocation. We have enabled automatic reordering , which can lead to smaller structures.
Provide the following structure:
struct Suboptimal(u8, u16, u8);
In previous versions of Rust on the x86_64 platform, this structure will occupy six bytes in memory. But looking at the code, you expect only 4. The additional two bytes appear due to alignment: since the largest type is in the u16
structure, it must be aligned by two bytes. But in this case, the u16
is located in memory with an offset of one byte. To place it with an offset of two bytes, you need to add another alignment byte after the first u8
. Adding one more byte after the second u8
, we get:
1 + 1 () + 2 + 1 + 1 () = 6
.
But what if our structure looks like this?
struct Optimal(u8, u8, u16);
This structure is optimally aligned; u16
is aligned with two bytes, as is the structure as a whole. No alignment required. This gives us 1 + 1 + 2 = 4
.
When designing Rust, we left the details of the placement in memory undefined for this very reason. Not adhering to a certain policy, we can make optimization, for example, as in this case, when the compiler can optimize Suboptimal
in Optimal
automatically. And if you check the sizes of Suboptimal
and Optimal
in Rust 1.18.0, you will see that they both are 4 bytes in size.
We planned this change for a long time; previous versions of Rust included this optimization in nightly builds, but some people wrote unsafe code that required accurate memory placement data. We rolled back this change and fixed all the similar cases that we knew about. But if you find any code that does not work correctly, let us know so that we can fix it!
We planned to move rustdoc
to rustdoc
's Markdown-compatible parser for a long time. However, a simple transition can lead to problems, since the CommonMark specification is different from our current parser, Hoedown. As part of our transition plan, a rustdoc
, --enable-commonmark
. This flag includes the use of a new parser instead of the old one. Please try it! As far as we know, both parsers produce the same results, but we want to know if you find a scenario in which their results differ!
Finally, rustc
compilation itself rustc
now 15% -20% faster . The commit messages in this PR contain some details; There were many ineffective places, but now they are all fixed.
See the detailed release notes for details.
Seven new APIs have been stabilized in this release:
Child::try_wait
, non-blocking version of Child::wait
.HashMap::retain
and HashSet::retain
add a retain
from Vec<T>
API for these two repositories.PeekMut::pop
allows you to pull the top element out of BinaryHeap<T>
after you have read it without having to arrange the heap a second time.TcpStream::peek
, UdpSocket::peek
, UdpSocket::peek_from
allows you to view a stream or socket.See the detailed release notes for details.
Cargo has added support for Pijul VCS, written in Rust.cargo new my-awesome-project --vcs=pijul
includes it!
In addition to the --all
flag, Cargo now has several new flags , for example --bins
, --examples
, --tests
and --benches
, which allow you to collect all the programs of a given type.
Finally, Cargo now supports Haiku and Android !
See the detailed release notes for details.
Many people participated in the creation of Rust 1.18. We could not achieve this without the help of each of you. Thank!
From translator
Thanks to Gordon-F and ozkriff for the help in translation.
Source: https://habr.com/ru/post/330778/
All Articles