























The Rust team is happy to announce a new version of Rust, 1.33.0. Rust is a programming language that is empowering everyone to build reliable and efficient software.
If you have a previous version of Rust installed via rustup, getting Rust 1.33.0 is as easy as:
$ rustup update stable
If you don't have it already, you can get rustup from the
appropriate page on our website, and check out the detailed release notes for
1.33.0 on GitHub.
The two largest features in this release are significant improvements to
const fns, and the stabilization of a new concept: "pinning."
const fn improvementsWith const fn, you can now do way more
things! Specifically:
const fn foo((x, y): (u8, u8)) { ... })let bindings (e.g. let x = 1;)let bindings (e.g. let mut x = 1;)x = y) and assignment operator (e.g. x += y)
expressions, even where the assignment target is a projection (e.g. a struct
field or index operation like x[3] = 42)3;)You're also able to call const unsafe fns inside a const fn, like this:
const unsafe fn foo() -> i32 { 5 }
const fn bar() -> i32 {
unsafe { foo() }
}
With these additions, many more functions in the standard library are able to
be marked as const. We'll enumerate those in the library section below.
This release introduces a new concept for Rust programs, implemented as two
types: the std::pin::Pin<P>
type, and the Unpin
marker trait. The core
idea is elaborated on in the docs for
std::pin:
It is sometimes useful to have objects that are guaranteed to not move, in the sense that their placement in memory does not change, and can thus be relied upon. A prime example of such a scenario would be building self-referential structs, since moving an object with pointers to itself will invalidate them, which could cause undefined behavior.
A
Pin<P>ensures that the pointee of any pointer typePhas a stable location in memory, meaning it cannot be moved elsewhere and its memory cannot be deallocated until it gets dropped. We say that the pointee is "pinned".
This feature will largely be used by library authors, and so we won't talk a
lot more about the details here. Consult the docs if you're interested in
digging into the details. However, the stabilization of this API is important
to Rust users generally because it is a significant step forward towards a
highly anticipated Rust feature: async/await. We're not quite there yet,
but this stabilization brings us one step closer. You can track all of the
necessary features at areweasyncyet.rs.
_You can now import an item as
_. This allows you to
import a trait's impls, and not have the name in the namespace. e.g.
use std::io::Read as _;
// Allowed as there is only one `Read` in the module.
pub trait Read {}
See the detailed release notes for more details.
Here's all of the stuff that's been made const:
overflowing_{add, sub, mul, shl, shr} are now const
functions for all numeric types.rotate_left, rotate_right, and wrapping_{add, sub, mul, shl, shr}
are now const functions for all numeric types.is_positive and is_negative are now const functions for
all signed numeric types.get method for all NonZero types is now const.count_ones, count_zeros, leading_zeros, trailing_zeros,
swap_bytes, from_be, from_le, to_be, to_le are now const for all
numeric types.Ipv4Addr::new is now a const functionAdditionally, these APIs have become stable:
unix::FileExt::read_exact_at and unix::FileExt::write_all_atOption::transpose and Result::transposeconvert::identitypin::Pin and marker::Unpin (mentioned above)marker::PhantomPinnedVec::resize_with and VecDeque::resize_withDuration::as_millis, Duration::as_micros, and Duration::as_nanosSee the detailed release notes for more details.
Cargo should now rebuild a crate if a file was modified during the initial build.
See the detailed release notes for more.
As previously announced, coinciding with this release, crates.io
will require that you have a verified email address to publish. Starting at
2019-03-01 00:00 UTC, if you don't have a verified email address and run cargo publish, you'll get an error.
This ensures we can comply with DMCA procedures. If you haven't heeded the warnings cargo printed during the last release cycle, head on over to crates.io/me to set and verify your email address. This email address will never be displayed publicly and will only be used for crates.io operations.
Many people came together to create Rust 1.33.0. We couldn't have done it without all of you. Thanks!
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。