The Rust team is pleased to present the release of Rust 1.19. Rust is a system programming language aimed at speed, security, and parallel code execution.
If you have a previous version of Rust installed, just update it with:
$ rustup update stable
If Rust is not yet installed, you can rustup
from the corresponding page of our website and read the detailed release notes for Rust 1.19 on GitHub.
Rust 1.19.0 includes some long-awaited features, but for starters, a note for Windows users. On this OS, Rust uses to build link.exe
, which is included in the "Microsoft Visual C ++ Build Tools". In the latest release of Visual Studio 2017, the directory structure for these tools has changed. Because of this, you were forced to use the tools of version 2015 or change the environment variables (for example, by running vcvars.bat
). In Rust 1.19.0, rustc
knows how to find the tools of version 2017, so you no longer need to use workarounds.
And now to the new features! Rust 1.19.0 is the first release to support the union
:
union MyUnion { f1: u32, f2: f32, }
Associations are similar to enum
( ), but they do not have "tags" unlike the latter. The "label" in
enum
allows you to find out at runtime which of the listed options is stored in a variable.
Since we can misinterpret the data stored in the union, and Rust cannot verify it for us, reading and writing the fields of the associations are unsafe:
let u = MyUnion { f1: 1 }; unsafe { u.f1 = 5 }; let value = unsafe { u.f1 };
Pattern matching also works:
fn f(u: MyUnion) { unsafe { match u { MyUnion { f1: 10 } => { println!(""); } MyUnion { f2 } => { println!("{}", f2); } } } }
When are joins useful? The main area of application is that interaction with C. C APIs can (and often do) provide unions, so writing wrappers for the API is much simpler. Also, from this RFC :
The built-in language support for unions also makes it possible to simplify the implementation of memory-efficient or cache-based structures based on the representation of values, such as computer-sized unions, using the lower bits of aligned pointers.
This possibility has been expected for a long time, and there are many more things that should be improved. At the moment, associations can only include types that implement Copy
, and cannot implement Drop
. We hope to remove these restrictions in the future.
By the way, have you ever wondered how new features are added to Rust? Associations were proposed by Josh Triplett, and he spoke at RustConf 2016 , talking about the integration process. You should take a look at this!
To other news, loop
can now return values via break
:
// let x; loop { x = 7; break; } // let x = loop { break 7; };
Rust has traditionally positioned itself as an "expression-oriented language", most syntax constructs return values, and are not statements. loop
stood out somewhat from this series, not returning a value.
What about the other cycles? It's not clear yet, see the discussion in this RFC .
A small improvement: closures that do not capture the environment can now be brought to the function pointer :
let f: fn(i32) -> i32 = |x| x + 1;
Now we provide xz
and use them by default, which allows us to speed up the transfer of data. Compression with gzip
is still available, in case you cannot use xz
for any reason.
The compiler can now run on Android . For a long time, we strongly supported the development on Android, and our support continues to improve.
In conclusion, about compatibility. Earlier, when we moved to Rust 1.0, we did a lot of work to make sure that everything was marked as “stable” and “not stable”. However, we looked at one thing: -Z
flags. -Z
compiler flag includes unstable flags. Unlike everything else, you can use -Z
with stable Rust. In April 2016, in Rust 1.8, we added a warning when using -Z
with the stable and beta versions of Rust. More than a year later, we fixed this hole in our history of stability by -Z
everywhere except for the compiler’s nightly builds .
See the detailed release notes for details.
The biggest changes in the standard library are eprint!
and eprintln!
. They work just like print!
and println!
but write to standard error output, not to standard output.
Other changes:
String
now implements FromIterator<Cow<'a, str>>
and Extend<Cow<'a, str>>
Vec
now implements From<&mut [T]>
Box<[u8]>
now implements From<Box<str>>
SplitWhitespace
now implements Clone
[u8]::reverse
now 5 times faster and [u16]::reverse
now 1.5 times fasterAnd some stabilized APIs:
See the detailed release notes for details.
In this release, a small but important improvement has been added to Cargo. The largest of them: Cargo now works directly with git-objects . This reduces the size of the registry and speeds up cloning, especially on Windows.
Other improvements:
(crate).
: println!("cargo:rustc-env=FOO=bar");
--all
for the cargo bench
subcommand to run tests --exclude
to exclude some containers when using --all
.--features
now accepts multiple values, separated by a comma or See the detailed release notes for details.
A lot of people participated in the development of Rust 1.19. We could not achieve this without the participation of each of you. Thank!
From translator
Thanks to ozkriff and gordon-f for help in translating
Source: https://habr.com/ru/post/334068/
All Articles