Mara Bos Profile picture
2 Dec, 11 tweets, 5 min read
🦀✨ @rustlang 1.57.0 was released just moments ago!…

As usual, a thread to highlight some of the new features:

1. panic!() and assert!() can now be used in const fns.

Any formatting other than panic!("..") and panic!("{}", some_str) is not accepted though, because formatting is not const (yet!).

2/11 const fn f<T>() {     assert!(std::mem::size_of::<T>() < 4);error[E0080]: evaluation of constant value failed  --> src/m
2. Many functions in the standard library have been marked as #[must_use], to warn you when just calling the function without using its result is most likely a mistake.

(See the full list here:…)

3/11 let mut a: f64 = 180.0;  a.to_radians(); // Doesn't change twarning: unused return value of `core::f64::<impl f64>::to_r
3. Iterator::map_while.

Basically a combination of map and take_while: Your closure is used to map each item, but can return None when it's done.

4/11 let a = [1, 2, 3, 4, 0, 5, 6];  let v: Vec<i32> = a     .int
4. Custom Cargo profiles!

Next to the standard Cargo profiles such as `release`, you can now define your own profiles with custom settings:

5/11 # Cargo.toml  ...  [profile.release-with-checks] inherits = $ cargo r --profile=release-with-checks    Compiling example
5. A dot or question mark after a braced macro invocation is no longer an error:

m! { .. }.method(); // ok!
m! { .. }?; // ok!


6. Fallible allocation.

Vec, String, VecDeque, HashMap and HashSet now have a .try_reserve() method. This method is similar to .reserve(), except it doesn't panic/abort when it was unable to allocate memory.

7/11 Screenshot of the reference documentation of Vec::try_reserv
7. Vec::leak no longer reallocates.

Vec::leak used to shrink the capacity before leaking the data, which might involve a reallocation. The behaviour is now changed to always leak the current allocation, without shrinking/reallocating first.

8/11 Screenshot of the documentation of Vec::leak, with one parag
8. std::hint::unreachable_unchecked is now const.

In *const* context, it'll result in a compiler error when reached, not in undefined behaviour like it would at runtime.

9/11 const unsafe fn unwrap_unchecked(opt: Option<i32>) -> i32 {
9. There's a few new tier 3 targets:

- armv6k-nintendo-3ds
- armv7-unknown-linux-uclibceabihf
- m68k-unknown-linux-gnu
- aarch64-kmc-solid_asp3
- armv7a-kmc-solid_asp3-eabi
- armv7a-kmc-solid_asp3-eabihf


And that's all I wanted to highlight in this thread!

For a more complete list of changes in Rust 1.57, check the release notes:




• • •

Missing some Tweet in this thread? You can try to force a refresh

Keep Current with Mara Bos

Mara Bos Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!


Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @m_ou_se

21 Oct
A few hours ago, @rustlang 1.56 was released! 🦀

This version ships with the new edition: Rust 2021! 🐊✨🎊

There's quite a few new features in the new version and edition:

Starting today, `cargo new` will use `edition = "2021"`. You can migrate your 2018 crates with `cargo fix --edition`.

These are all the edition changes:

1. `array.into_iter()` now iterates by value, instead of giving references.

(See for details.)

2/17 for (i, x) in [1, 2, 3].into_iter().enumerate() {        //
2. Closures in Rust 2021 will capture only the fields of an object you use, instead of the entire object. This should result in fewer fights with the borrow checker:

3/17 let mut x = ("a".to_string(), "b".to_str
Read 17 tweets
9 Sep
🦀 Happy new Rust! 🎆

Just now, @rustlang 1.55 was released, shipping with some small but very nice improvements.…

A thread:
🦀 1. Half-open ranges in patterns.

Next to `start..=end`, you can now also use `start..` as a pattern to match on: fn f(x: u32) {     match x ...
🦀 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: // Much faster! let a: f64 ...
Read 11 tweets
6 May
The new stable version of @rustlang, Rust 1.52, was released just now! 🦀🎉

This release contains quite a few new small but significant features.

A thread.

My favourite new addition is `str::split_once`.

We already had str::split and str::splitn, which result in an iterator. But when parsing something simple, you often want to split something exactly once. For example, to parse a string containing `key=value`.

2/10   let s = "hello=world";   let (key, val) = s.spliScreenshot of the split_once and rsplit_once documentation.
Another one I'm excited about is one of the first features I worked on: std::fmt::Arguments::as_str()

fmt::Arguments is returned by format_args!(), and appears in macros that support formatting.

as_str() allows handling the literal case without special-casing your macro:

3/10 // Before  macro_rules! log {     ($msg:literal) => {       // After  macro_rules! log {     ($($args:tt)*) => {
Read 10 tweets
24 Apr
I just approved the PR for a very exciting addition to @rustlang 1.53: IntoIterator for arrays 🎉🦀

Before this change, only references to arrays implemented IntoIterator, which meant you could iterate over &[1,2,3] and &mut [1,2,3], but not over [1,2,3] directly.

1/6 error[E0277]: `[{integer}; 3]` is not an iterator  borrow thfor e in [1, 2, 3] { // Works in 1.53!     println!("{}
The reason we didn't add it sooner was backwards compatibility. `array.into_iter()` already compiles today, because of the way methods get resolved in Rust. This implicitly calls `(&array).into_iter()`. Adding the trait implementation would change the meaning and break code.

2/6 for e in [1, 2, 3].into_iter() {     // Surprise: `e` is a r
Technically we consider this type of breakage (adding a trait impl) 'minor' and acceptable. But there was too much code that would be broken by it. Thanks to @LukasKalbertodt, such code results in a warning nowadays, but there's a lot of code that just doesn't get updated.

3/6 warning: this method call currently resolves to `<&[T; N] as
Read 6 tweets
22 Apr
Lots of new standard library additions will become stable in @rustlang 1.53. 🦀🎉

1. Duration::ZERO, Duration::is_zero(), Duration::MAX pub const ZERO: Duration  A...
2. Duration::saturating_{add,sub,mul}

Since Durations cannot represent negative values, saturating_sub might come in handy to avoid panics. pub fn saturating_add(self, fn saturating_sub(self,...
Read 17 tweets

Did Thread Reader help you today?

Support us! We are indie developers!

This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!


0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy


3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!