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.
3/11
Option and Result now have an unsafe unwrap_unchecked() function. If you're absolutely sure that the Option contains a Some, or the Result contains an Ok, you can use these to unwrap the value while skipping any checks. (Getting this wrong means undefined behaviour though!)
4/11
Path and Metadata now have an is_symlink() method. This saves some typing, as previously this had to be done with std::fs::symlink_metadata(path) followed by metadata.file_type().is_symlink().
5/11
In Rust 1.57, many library functions got the #[must_use] attribute to prevent subtle mistakes. With Rust 1.58, this effort is now completed, and all functions that should have #[must_use] according to the accepted guidelines now have that attribute.
The `Command` api now no longer searches the current working directory on Windows, to match the behaviour on other platforms. This will prevent problems like CVE-2021-3013: cve.org/CVERecord?id=C…
7/11
Many file operations like File::open(), fs::create_dir(), etc. now all work with long paths on Windows. The paths are automatically canonicalized and prefixed by \\?\, which is how extended-length paths are expressed on Windows.
8/11
Const evaluation got a bit more powerful again. You can now dereference pointers in const context. Only *const though, not *mut.
9/11
And the last thing I want to highlight in this thread:
Rustdoc now shows methods from all recursive Deref implementations, instead of only the outermost one. So if your type is Deref<Target = String>, it now not only shows the String methods, but also all the str methods.
10/11
And that's the end of today's thread!
For a more complete list of changes in Rust 1.58, check 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.