Release Rust 1.28

Original author: The Rust Core Team
  • Transfer

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. With the detailed release notes Rust 1.28.0 is available on GitHub.


What is included in the stable version 1.28.0


Global allocators


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 is stabilized #[global_allocator], 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 a system allocator, which can be used to switch to the use of a system allocator, when necessary, by a static declaration with an attribute #[global_allocator].


use std::alloc::System;
#[global_allocator]static GLOBAL: System = System;
fnmain() {
    letmut 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 .


Improved formatting error message


The 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 formatstring: 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 nameinformat string
  |
  = note: argument names cannot startwith an underscore

See the release notes for details .


Standard Library Stabilization


In addition to the stabilization of the type already mentioned GlobalAlloc, NonZeronumerical types are stabilized in this issue . This type wrapper around standard unsigned integer types: NonZeroU8, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU128and NonZeroUsize.


They allow you to optimize the size of the stored data. For example, it Option<u8>takes two bytes, whereas Option<NonZeroU8>- one. Note that this optimization is maintained even when NonZeroU8wrapped inside another structure; the example below shows that it Doorstill takes one byte, even when it is placed inside Option. This optimization is also applicable to user-defined enums; Optionthis is not special here.


use std::mem;
use std::num::NonZeroU8;
structKey(NonZeroU8);
structDoor {
    key: Key,
}
fnmain() {
    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 .


Improvements in Cargo


Cargo now will not allow you to publish packages with build scripts that modify the src directory. The catalog srcin the package should be considered immutable.


Developers 1.28.0


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


Also popular now: