Mara Bos Profile picture
22 Apr, 17 tweets, 6 min read
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,...
3. Option::insert

`opt.insert(1)` does the same as `opt = Some(1)`, but also gives you a mutable reference to the `1` inside that Some after it's stored in the Option. pub fn insert(&mut self, va...
4. {integer}::BITS

I already promised this one for Rust 1.51, but we had to temporarily revert it. Trying again now for 1.53 :)

5. BufReader::seek_relative

Unlike the seek() function from the Seek trait, this one does not return the current position in the stream, which allows the BufReader to perform the seek without accessing the underlying reader if the new position lies within the buffer. impl<R: Seek> BufReader<R> ...
6. NonZero*::leading_zeros() and NonZero*::trailing_zeros()

These avoid the zero-check that the same functions on the regular integer types need to do, since on many architectures, the corresponding native instruction doesn't handle the zero case.

These are both `const fn`s. pub const fn leading_zeros(...
7. std::array::from_ref and std::array::from_mut

These can safely convert a &T to &[T; 1] or &mut T to &mut [T; 1]. Function std::array::from_r...
8. f32::is_subnormal and f64::is_subnormal

A way to easily check if a floating point number is subnormal. pub fn is_subnormal(self) -...
9. DebugStruct::finish_non_exhaustive()

This allows you to mark the custom Debug representation of your type with fmt.debug_struct() to not be exhaustive. It adds two dots before the closing brace.

We've also updated the std types' Debug impls to consistently use this. pub fn finish_non_exhaustiv...
10. AtomicPtr::fetch_update and AtomicBool::fetch_update

We already had this one on the other atomic types, but they were missing on atomic pointers and booleans. pub fn fetch_update<F>(    ...
11. Peekable::peek_mut()

This allows you to mutate the peeked value which will be returned next by the Iterator. pub fn peek_mut(&mut self) ...
12. OsStr::{make_ascii_lowercase, make_ascii_uppercase, to_ascii_lowercase, to_ascii_uppercase}

We already had these on `str`s, but these new ones can be applied to an OsStr directly even if it's not valid UTF-8. pub fn make_ascii_lowercase...
13. std::cmp::{min_by, max_by, min_by_key, max_by_key}

Like `std::cmp::{min, max}`, but allows you to specify the way the values are compared. Function std::cmp::min_by_k...
14. io::ErrorKind::Unsupported

A new ErrorKind which is used when the operation is not supported by the system. (E.g. ENOSYS on Unix and ERROR_CALL_NOT_IMPLEMENTED on Windows.)

Previously these fell under io::ErrorKind::Other. Unsupported  This operation...
15. BTreeMap::retain and BTreeSet::retain

Just like Vec::retain, these allow you to filter out some entries from the collection based on a predicate.

In case of the BTreeMap, you get access to both the key and the value, and can mutate the values if needed. pub fn retain<F>(&mut self,...
And that's the end of this thread. :)

Thanks to everyone involved in the design, implementation and stabilization of all these features! 💛

I probably missed a few stabilizations, and there will be even more since Rust 1.53 is still under development. So stay tuned. 🙂

• • •

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

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}; ...for e in [1, 2, 3] { // Wor...
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_ite...
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 c...
Read 6 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!