Mara Bos Profile picture
9 Sep, 11 tweets, 5 min read
πŸ¦€ 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 ...
πŸ¦€ 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: $ cargo test warning: funct...
πŸ¦€ 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. match some_error.kind() {  ...
πŸ¦€ 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: let a = [1, 2, 3];  let b =...
πŸ¦€ 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`: use std::ops::ControlFlow; ...
πŸ¦€ 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. let mut m = MaybeUninit::un...
πŸ¦€ 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: static S: &str = unsafe { s...
πŸ¦€ 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: $ cargo clippy --fix     Ch...
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:


β€’ β€’ β€’

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

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 Become our Patreon

Thank you for your support!

Follow Us on Twitter!