Mara Bos Profile picture
Rust dev, Electronics engineer, Founder/CTO of Fusion Engineering, @rustlang Library team lead, ADHD, Polyamorous, Lesbian, She/Her

Sep 9, 2021, 11 tweets

🦀 Happy new Rust! 🎆

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

blog.rust-lang.org/2021/09/09/Rus…

A thread:

🦀 1. Half-open ranges in patterns.

Next to `start..=end`, you can now also use `start..` as a pattern to match on:

🦀 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:

🦀 3. No more duplicate errors.

Cargo invocations like `cargo test`, which check multiple configurations of the the code, will no longer produce duplicate diagnostics, and instead only report the number of duplicates:

🦀 4. No more ErrorKind::Other errors from std.

The Other io::ErrorKind is now only for custom errors, and std no longer produces such io::Errors. Uncategorized errors can no longer be directly matched on, such that we can categorize them later without breaking things each time.

🦀 5. The array​.map function.

Iterators already had a `.map()` function, but that would result in an iterator, not an array, which does not statically know its length anymore. If you want to map the values of a [T; 3] to some [U; 3], you can now use `.map()` directly on arrays:

🦀 6. std::ops::ControlFlow.

An enum with two variants: Break and Continue. It is similar to Result, but without calling the cases 'okay' and 'error'.

It's part of the larger 'try v2' feature which is still in development. It can already be used through `iterator.try_for_each`:

🦀 7. A few methods on MaybeUninit.

.write() allows you to write into a MaybeUninit and get a &mut T to what you wrote, without writing any unsafe blocks.

.assume_init_ref() and .assume_init_mut() are unsafe, but allow you to get a reference without first needing a raw pointer.

🦀 8. const std::str::from_utf8_unchecked.

The unsafe from_utf8_unchecked function is now const. If you're sure that some bytes you already have at compile time are valid utf-8, you can now directly turn them into a static or const &str:

🦀 9. cargo clippy --fix

Just like `cargo fix` applies the suggestions from Rustc's warnings, `cargo clippy --fix` will automatically apply the suggestions from Clippy to your code:

And with that, I'm ending this thread. 🧵🏁

For more details and all the other changes and additions in Rust 1.55.0, see the announcement and the release notes:

Rust: github.com/rust-lang/rust…
Cargo: github.com/rust-lang/carg…
Clippy: github.com/rust-lang/rust…

blog.rust-lang.org/2021/09/09/Rus…

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling