Next to `start..=end`, you can now also use `start..` as a pattern to match on:
π¦ 2. A better and faster floating point parsing algorithm in the standard library.
Functions like f64::from_str are now much faster, and a bunch of edge cases that failed to parse before are solved:
π¦ 3. No more duplicate errors.
Cargo invocations like `cargo test`, which check multiple configurations of the the code, will no longer produce duplicate diagnostics, and instead only report the number of duplicates:
π¦ 4. No more ErrorKind::Other errors from std.
The Other io::ErrorKind is now only for custom errors, and std no longer produces such io::Errors. Uncategorized errors can no longer be directly matched on, such that we can categorize them later without breaking things each time.
π¦ 5. The arrayβ.map function.
Iterators already had a `.map()` function, but that would result in an iterator, not an array, which does not statically know its length anymore. If you want to map the values of a [T; 3] to some [U; 3], you can now use `.map()` directly on arrays:
π¦ 6. std::ops::ControlFlow.
An enum with two variants: Break and Continue. It is similar to Result, but without calling the cases 'okay' and 'error'.
It's part of the larger 'try v2' feature which is still in development. It can already be used through `iterator.try_for_each`:
π¦ 7. A few methods on MaybeUninit.
.write() allows you to write into a MaybeUninit and get a &mut T to what you wrote, without writing any unsafe blocks.
.assume_init_ref() and .assume_init_mut() are unsafe, but allow you to get a reference without first needing a raw pointer.
π¦ 8. const std::str::from_utf8_unchecked.
The unsafe from_utf8_unchecked function is now const. If you're sure that some bytes you already have at compile time are valid utf-8, you can now directly turn them into a static or const &str:
π¦ 9. cargo clippy --fix
Just like `cargo fix` applies the suggestions from Rustc's warnings, `cargo clippy --fix` will automatically apply the suggestions from Clippy to your code:
And with that, I'm ending this thread. π§΅π
For more details and all the other changes and additions in Rust 1.55.0, see the announcement and the release notes:
ππ¦ Just an hour ago, #rustlang 1.66.0 was released!
As usual, here's a thread with some of the highlights. π§΅
1/12
Rust 1.66 comes with std::hint::black_box(), a function that does nothing. However, the compiler tries its very best to pretend it doesn't know what it does.
It is useful in benchmarks, to prevent the compiler from optimizing your entire benchmark away.
2/12
The Option type got a new method: Option::unzip(). It's basically the opposite of Option::zip(): it splits an Option of a pair into a pair of Options.
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.
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.