The Rust development team is pleased to announce the release of a new version of Rust: 1.28.0. Rust is a system programming language aimed at security, speed, and parallel code execution.
If you have a previous version of Rust installed using rustup, then to update Rust to version 1.28.0, you just need to run:
$ rustup update stable
If you have not yet installed rustup, you can install it from the corresponding page of our website. Detailed notes for the release of Rust 1.28.0 can be found on GitHub.
Using the allocators of the Rust program, memory is acquired at run time. Previously, Rust did not allow changing the way memory was allocated, which limited its use in some cases. On some platforms, jemalloc was used, on others, a system allocator, but users could not control this. In release 1.28.0, the attribute #[global_allocator]
stabilized, which allows programs on Rust to select a system allocator, as well as define new allocators, implementing the type GlobalAlloc
.
The default allocator for Rust programs on some platforms is jemalloc. The standard library now provides a descriptor for the system allocator, which can be used to switch to using the system allocator, when necessary, by a static declaration with the #[global_allocator]
attribute.
use std::alloc::System; #[global_allocator] static GLOBAL: System = System; fn main() { let mut v = Vec::new(); // . v.push(1); }
However, sometimes you need to define your own allocator for a specific functional area of your application. This is also relatively easy to do by implementing the type GlobalAlloc
. You can read more about how to do this in the documentation .
Work on improving diagnostics continues, this time with an emphasis on formatting:
format!("{_foo}", _foo = 6usize);
Previously, the error message in this place was rather meager:
error: invalid format string: expected `'}'`, found `'_'` | 2 | format!("{_foo}", _foo = 6usize); | ^^^^^^^^
Now the new diagnostic message indicates the specific reason why the format string is invalid:
error: invalid format string: invalid argument name `_foo` | 2 | let _ = format!("{_foo}", _foo = 6usize); | ^^^^ invalid argument name in format string | = note: argument names cannot start with an underscore
See the release notes for details.
In addition to the already mentioned stabilization of the GlobalAlloc
type, in this issue NonZero
stabilized numeric types. These are wrapper types around standard unsigned integer types: NonZeroU8
, NonZeroU16
, NonZeroU32
, NonZeroU64
, NonZeroU128
and NonZeroUsize
.
They allow you to optimize the size of the stored data. For example, Option<u8>
is two bytes, while Option<NonZeroU8>
is one. Note that this optimization is preserved even when NonZeroU8
wrapped inside another structure; the example below shows that Door
still occupies one byte, even when it is placed inside Option
. This optimization also applies to user-defined enums; Option
not special here.
use std::mem; use std::num::NonZeroU8; struct Key(NonZeroU8); struct Door { key: Key, } fn main() { assert_eq!(mem::size_of::<Door>(), 1); assert_eq!(mem::size_of::<Option<Door>>(), 1); }
Many other library components have also been stabilized, a full list of which can be found in the detailed release notes .
Cargo will no longer allow you to publish packages with build scripts that modify the src directory. The src
directory in the package should be considered immutable.
A lot of people participated in the development of Rust 1.28. We could not complete the work without the participation of each of you. Thank!
From the translator: I express my hotel thanks to the members of the ruRust community and personally to ozkriff for their help with translation and proofreading
Source: https://habr.com/ru/post/419259/
All Articles