Mara Bos
Mara Bos

@m_ou_se

12 Tweets Feb 06, 2023
🆕🦀 A bit more than a week ago, @rustlang 1.60.0 was released! ✨
Here's a thread with ten highlights from this release:
1/12
blog.rust-lang.org
First: cargo --timings
Cargo now has a new command line flag, --timings, to make it generate a detailed report on how much time was spent on each of the the steps involved in compiling your program.
2/12
Then, another improvement to Cargo: more flexible optional features.
You can now use "dep:" to refer to an optional dependency with the same name as a feature. And you can use a question mark to enable a feature on a dependency only if that optional dependency is enabled.
3/12
Next: new #[cfg] abilities.
#[cfg(panic = "abort")] and #[cfg(panic = "unwind")] lets you detect if your code is compiled in abort-on-panic mode or in unwind-on-panic mode.
#[cfg(target_has_atomic = "N")] allows you to detect if the target supports N bit atomics.
4/12
Moving on to library features, starting with an implementation change:
Subtracting a later Instant from an earlier one will no longer panic, but result in a zero Duration instead.
This prevents spurious panics on systems where the monotonic clock isn't strictly monotonic.
5/12
All integer types now have an .abs_diff() method, giving you the absolute difference between two integers.
It's mostly equivalent to (a - b).abs(), except it never overflows and always returns an unsigned type.
6/12
Arc and Rc both got a new constructor function, called new_cyclic().
It gives you access to a weak pointer to the new allocation that you can use in the value that you're wrapping in the Arc/Rc, which helps with making cyclic structures.
7/12
Wrapping<T> now implements AddAssign<T>, SubAssign<T>, etc. This means you can use operators like += and -= on Wrapped without wrapping the right hand side of the assignment.
8/12
To make it easier to write correct unsafe code, MaybeUninit now has two more methods:
- assume_init_read, to take the initialized value without consuming the MaybeUninit.
- assume_init_drop, to drop the initialized value in place (also without consuming the MaybeUninit).
9/12
Another new feature that helps with unsafe code is Vec::spare_capacity_mut.
It gives you a mutable reference to the free space at the end, after the last element. Sometimes it's useful to write to that memory directly, and then make it part of the Vec with set_len.
10/12
And finally, the last addition I want to highlight in this thread: is_aarch64_feature_detected!().
This macro allows you to check, at runtime, if a certain feature is available on Aarch64 (64-bit ARM), similar to is_x86_feature_detected!().
11/12
And that's all I wanted to highlight for now!
For a more complete list of changes in Rust 1.60, check the release notes:
Rust: #version-1600-2022-04-07" target="_blank" rel="noopener" onclick="event.stopPropagation()">github.com
Cargo: #cargo-160-2022-04-07" target="_blank" rel="noopener" onclick="event.stopPropagation()">github.com
Clippy: #rust-160" target="_blank" rel="noopener" onclick="event.stopPropagation()">github.com
Enjoy! ✨🦀
12/12

Loading suggestions...