Rust now has a new async-related trait: IntoFuture.
The .await syntax be used on anything that implements IntoFuture. (Similar to how, with a for loop, you can iterate over anything that implements IntoIterator.)
This allows types to provide easier async interfaces.
2/15
Today's Rust release also comes with two more async-related tools:
The std::future::poll_fn function allows you to easily create a future from a closure (like iter::from_fn for iterators).
The std::task::ready!() macro extracts a Poll::Ready, or returns early on Pending.
3/15
The Rust's NonZero types got new methods for (unsigned) addition, multiplication, exponentiation, absolute numbers, and next-power-of-two calculation, that all preserve "non-zero-ness": they return a NonZero type, because we know the result is never zero.
4/15
The types for interfacing with C, such as std::os::raw::c_int and c_void, have been moved to core::ffi. They are still available in the old (and new) location in `std`, but are now also available in `core`, for #![no_std] programs.
5/15
The OsString type now implements std::fmt::Write, which means you can write to it using the write!() and writeln!() macros.
6/15
The IP and socket address types, Ipv4Addr, Ipv6Addr, SocketAddrV4 and SocketAddrV6 now use a minimal, trivial internal representation, instead the libc types.
This clears the way for moving these types to `core` (no_std), and using these in const fns, in the future.
7/15
The atomic compare_exchange functions no longer require the success memory ordering to be at least as strong as the failure ordering.
(The same restriction was dropped from C++ as part of C++17.)
For example, compare_exchange(a, b, Release, Acquire) is now accepted.
8/15
The std::slice::from_raw_parts function is now a const fn, allowing for even more code crimes at compile time. 😌
9/15
To allow for sound (unsafe) implementations of reference-counted allocated objects, it's no longer undefined behavior to keep a reference to something that's de-allocated, as long as you don't use it, and the object's bytes all reside in an UnsafeCell (e.g. an atomic).
10/15
Rust 1.64 is the last release that ships with the deprecated old language server, RLS. Instead, starting with this release, the rustup distribution now includes @rust_analyzer.
(Nothing changes for most users. E.g. the VS Code extension will keep handling updates itself.)
11/15
Cargo now makes it possible for a Cargo.toml file in a workspace to inherit dependencies and various package properties from the root Cargo.toml file. This makes it easier to handle large workspaces.
12/15
Cargo now also supports multiple --target flags, to build for more than one target at once.
13/15
Initial support for the Nintendo Switch has been added: aarch64-nintendo-switch-freestanding as a "tier 3" target.
This doesn't include the Rust standard library, but makes it easier to compile no_std Rust programs for this platform.
Cargo now has 'cargo add' built-in: a (sub)command to add a crate to your Cargo.toml. It automatically looks up the latest version, and shows you the available features of the crate.
See `cargo add --help` for more details.
2/9
On Linux and several BSDs, std::sync's Mutex, RwLock, and Condvar now no longer do any allocations. They used to be (heap-allocated) wrappers around pthread lock types, but have been replaced by a minimal, more efficient, futex-based implementations.
🦀 As of Rust 1.62 (going into beta this week), std::sync::Mutex, RwLock, and Condvar no longer do any allocations on Linux. 🎉
Benchmarking locks is extremely tricky, as their performance depends heavily on the exact use case, but there are very noticable differences:
std's Mutex basically used to contain a Pin<Box<pthread_mutex_t>>, where the pinned Box was only necessary because pthread_mutex_t is not guaranteed movable. The new Mutex no longer uses pthread, and instead directly uses the futex syscall, making it smaller and more efficient.
Also, the new RwLock on Linux prefers writers, which prevents writer starvation. pthread_rwlock_t prefers readers by default, to allow recursive read locking. Rust's RwLock does not make recursion guarantees, and on several platforms (including Windows) already preferred writers.
Newly stabilized in the standard library is File::options(). It's identical to OpenOptions::new(), but you don't have to import the OpenOptions type separately from the File type.
As usual, a thread to highlight some of the new features:
1/11
1. panic!() and assert!() can now be used in const fns.
Any formatting other than panic!("..") and panic!("{}", some_str) is not accepted though, because formatting is not const (yet!).
2/11
2. Many functions in the standard library have been marked as #[must_use], to warn you when just calling the function without using its result is most likely a mistake.
2. Closures in Rust 2021 will capture only the fields of an object you use, instead of the entire object. This should result in fewer fights with the borrow checker: