The Rust team is pleased to announce the new version of Rust: 1.25.0. Rust is a system programming language aimed at security, speed, and parallel code execution.
If you have a previous version of Rust installed, just update it with:
$ rustup update stable
If you have not yet installed rustup, you can install it from the corresponding page of our website. Detailed notes on the release of Rust 1.25.0 can be found on GitHub.
The last few releases were insignificant, but Rust 1.25 contains many
innovations! First: we updated LLVM from version 4 to version 6. Update
entails a number of changes, the most important of which is AVR support.
There is a new way to use the use operator: nested groups . If you imported in this way:
use std::fs::File; use std::io::Read; use std::path::{Path, PathBuf};
Now you can write like this:
// use std::{fs::File, io::Read, path::{Path, PathBuf}}; // use std::{ fs::File, io::Read, path::{ Path, PathBuf } };
This can reduce repetition and make the code more understandable.
In this issue, we have presented two major changes in the documentation. First of all: Rust By Example is now at doc.rust-lang.org ! Soon we will redirect from the old domain. We hope that this will draw more attention to the beautiful resource and you will receive a local copy with your local documentation.
Secondly, in Rust 1.23 we talked about the transition from Hoedown to pulldown-cmark. In Rust 1.25, pulldown-cmark is now the default. Finally, we removed the last part of the C code from rustdoc and now follow the CommonMark specification.
Finally, in RFC 1358 , the #[repr(align(x))]
attribute was adopted. In Rust 1.25 it has been stabilized ! This attribute allows you to set the alignment of your structures:
struct Number(i32); assert_eq!(std::mem::align_of::<Number>(), 4); assert_eq!(std::mem::size_of::<Number>(), 4); #[repr(align(16))] struct Align16(i32); assert_eq!(std::mem::align_of::<Align16>(), 16); assert_eq!(std::mem::size_of::<Align16>(), 16);
If you are working with low-level code, then control over such "things" can be very important!
See the release notes for details.
The biggest change in libraries is std::ptr::NonNull<T>
. This type is similar to *mut T
, but it is nonzero and covariant. This blog post is not the best place to explain the differences, but in two words: NonNull<T>
guarantees that it will not be null. This means that Option<NonNull<T>>
is the same size as *mut T
If you create a data structure with unsafe code, NonNull<T>
will often be the right choice for you!
libcore
time
, which contains the Duration
type, previously available only in libstd
.
In addition, the from_secs
and from_millis
associated with Duration
were written using const fn
, which allows them to be used to initialize Duration
, in constant expressions.
See the release notes for details.
There is one important change in the Cargo command line interface: cargo new
now by default generate an executable file instead of a library. We are trying to ensure that Cargo’s interface is fairly stable, but this is an important change and is unlikely to break the package manager.
For reference, cargo new
now accepts two flags: --lib
to create libraries and --bin
to create binary or executable files. In the previous version of Cargo, if you do not pass a single value, then the default flag is --lib
. We made this decision because each binary file (often) depends on many libraries and therefore they (libraries) are more common. However, this is not true. Each library uses many binary files. Moreover, when creating a new project, you often want it to be a program that you can run. This problem occurs not only among newbies, but even very long-time members of the community said that they found this behavior unexpected. So we change it.
Similarly, the previous version of the cargo new
command was a bit stubborn in the name of the packages. In particular, if the name of your package started with rust-
or ended with- -rs
, Cargo would rename it. The intention was that it is a package of the Rust language, and this is redundant information. However, people care a lot about naming and when confronted with this, they are surprised and often frustrated. Therefore, we will no longer do this .
Many users love the cargo doc
team — a way to generate documentation locally for their project. In this release, she received a speed increase , because now she works through cargo check
, and not cargo build
. Therefore, some scripts will run faster.
In addition, pumping out git dependencies should be faster , thanks to the use of hard links when possible.
See the release notes for details.
A lot of people participated in the development of Rust 1.25. We could not achieve this without the participation of each of you.
Translated by @ BORN2LOSE
Source: https://habr.com/ru/post/352800/
All Articles