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 https://blog.rust-lang.org/2021/05/06/Rust-1.52.0.html
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
You can follow @m_ou_se.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled: