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
• • •
Missing some Tweet in this thread? You can try to
force a refresh
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
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
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.