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

May 6, 2021, 10 tweets

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.

1/10

blog.rust-lang.org/2021/05/06/Rus…

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

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

Next: #[deny(unsafe_op_in_unsafe_fn)]

This forces you to write `unsafe` to call unsafe functions, even when inside an unsafe fn. Most unsafe functions have a mostly (or fully) safe implementation, so separating 'unsafe to call' from 'unsafe implementation' is often useful.

4/10

The casting operator (`as`) already allowed converting from a reference to an array to a pointer to the first element (from &[T; N] to *const T). Starting in Rust 1.52, this also works for the mutable case (from &mut [T; N] to *mut T):

5/10

Another important library feature: slice::partition_point.

This performs a binary search through a slice, given a (boolean) predicate.

With `<= x` or `< x` as the predicate, this is equivalent to the `upper_bound` and `lower_bound` algorithms of the C++ standard library.

6/10

If you like reference-counted errors, Rust 1.52 now implements the Error trait for all Arc<T> for which T itself implements Error:

7/10

As in most recent Rust releases, more functions are turned into `const fn`s to allow use in compile-time evaluated expressions.

This time it's the ascii upper-/lowercase functions, char::len_utf8 and len_utf16, and all the integer division/remainder functions:

8/10

The last new feature I want to highlight is a Rustdoc feature: Task lists.

With the same syntax that's supported by some other markdown variants (e.g. GitHub's), you can now add checked and unchecked checkboxes in your documentation:

9/10

And with that, I'm ending this thread. :)

There's a few more changes and additions, which you can find in the full release notes:
github.com/rust-lang/rust…

10/10

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