Rust 1.46.0 is released, and this version brings the following updates:
Improve const fn
Several core language features can now be used in const fn:
- if, if let, and match
- while, while let, and loop
- the && and || operators
Can also be converted to slice:
These functions may not be new, but since you can use all functions except const fn, they add a lot of compile-time computing power. For example, const-sha1 crate allows you to calculate SHA-1 hash value at compile time. This improves the performance of Microsoft’s Rust WinRT binding by 40 times.
#[track_caller]
The #[track_caller] attribute was first proposed in 2017. If you are writing a function like unwrap that may trigger panic, you can put this comment on the function, and the default panic formatter will use its caller as the location in the error message. For example, this is the previous unwrap:
just now:
If you implement the panic hook yourself, you can also use the caller method on std::panic::Location to access this information.
Library changes
In keeping with the theme of const fn improvement, std::mem::forget is now also a const fn. In addition, this version also stabilizes two new APIs:
- Option::zip
- vec::Drain::as_slice
Release Notes:
https://blog.rust-lang.org/2020/08/27/Rust-1.46.0.html
For more such interesting article like this, app/softwares, games, Gadget Reviews, comparisons, troubleshooting guides, listicles, and tips & tricks related to Windows, Android, iOS, and macOS, follow us on Google News, Facebook, Instagram, Twitter, YouTube, and Pinterest.