Mara Bos
Mara Bos

@m_ou_se

16 Tweets 2 reads Feb 06, 2023
🆕🦀 Just a few hours ago, Rust 1.61 was released! ✨
Here's a thread with fourteen highlights:
1/16
1. `const fn`s can now have trait bounds.
Traits can't have `const fn`s yet, so the use of this feature is limited, though. It does allow using associated constants and types, which makes it possible for more types to provide a const `new` function, which can be very useful.
2. `impl Trait` syntax can now be used in the signatures of `const fn`s, both as arguments and as the return type.
3. You now create `dyn` trait objects and function pointers and in `const fn`s, and pass them around.
4. Several methods on raw pointers are now `const`: offset, add, sub, wrapping_offset, wrapping_add, and wrapping_sub.
5. `impl Trait` return types now works for recursive functions:
6. std::process::Termination and std::process::ExitCode:
You can implement the Termination trait for your own type, which means your type can be used as the return type of `main`. Returning your type from main can have its own custom behavior and exit code.
7. Vec::retain_mut() and VecDeque::retain_mut().
These are the mutable version of Vec::retain() and VecDeque::retain(). They allow you to conditionally drop items from the collection, while also being able to modify them.
8. std::thread::JoinHandle::is_finished()
Using this method on JoinHandle, you can check whether the thread is still running or if it has finished, without having to block on .join()'ing it.
9. std::thread::available_parallelism() now takes cgroup quotas into account on Linux.
10. You can now create Unix socket SocketAddr objects from a path, using std::os::unix::net::SocketAddr::from_pathname.
11. std::io::stdin().lock(), std::io::stdout().lock() and std::io::stderr().lock() have had their return type slightly tweaked: they now return an object with a 'static lifetime, which means you no longer have to manually keep the intermediary object around:
12. Pin::static_ref()
This function allows you to safely consider a `static` object or leaked allocation 'pinned', as such an object can not safely be moved. This effectively makes the 'static lifetime of a reference satisfy the requirements of Pin.
13. impl Write for std::io::Cursor<[u8; N]>
You could already use `io::Cursor`s that borrow a slice, but now you can also use cursors that own (contain) their data as an array:
14. Tests ignored with #[ignore = "message"] now show their message as part of the test output:
And that's all I wanted to highlight!
For a more complete list of changes in Rust 1.61, check the release notes:
Rust: #version-1610-2022-05-19" target="_blank" rel="noopener" onclick="event.stopPropagation()">github.com
Cargo: #cargo-161-2022-05-19" target="_blank" rel="noopener" onclick="event.stopPropagation()">github.com
Clippy: #rust-161" target="_blank" rel="noopener" onclick="event.stopPropagation()">github.com
Enjoy! ✨🦀
16/16

Loading suggestions...