Mara Bos Profile picture
Aug 11 16 tweets 7 min read
🆕🦀 Just moments ago, @rustlang 1.63.0 was released! 🎉

It's quite a big release, with even more exciting new features than usual!

Here's a thread with some of the highlights. 🧵

1/16

blog.rust-lang.org/2022/08/11/Rus…
One of the features I'm most excited about is scoped threads! (Although I'm obviously biased, since I worked on this myself.)

As of today, you can use std::thread::scope() to spawn threads that borrow local variables, reducing the need for Arc! ✨

doc.rust-lang.org/stable/std/thr…

2/16 let mut a = vec![1, 2, 3]; let mut x = 0;  std::thread::scop
Another thing I'm very excited about, is that Mutex, RwLock and Condvar now all have a _const_ new function.

This means you can now have a static Mutex without having to use lazy_static or once_cell. ✨

3/16 use std::sync::Mutex;  static S: Mutex<String> = Mutex::new(
Another major addition are types and traits for the native file descriptors/handles/sockets of various platforms.

E.g. OwnedFd represents a Unix file descriptor that should be closed, while BorrowedFd borrows a file descriptor using a lifetime.

See doc.rust-lang.org/stable/std/os/…

4/16 // Unix: use std::os::unix::io::{BorrowedFd, OwnedFd};  exte  use std::fs::File; - use std::os::unix::io::{AsRawFd, RawF
A smaller but very useful new feature is std::array::from_fn.

Use it to create an array based on a closure, which is called for every index of the array.

Not only the element type, but also the number of elements can be automatically inferred from context.

5/16 let array = std::array::from_fn(|i| 100 * i);  assert_eq!(ar
VecDeque<u8> now implements both io::Read and io::Write, such that it can be used by generic I/O functions like io::copy and write!().

Write appends to the end (just like Write for Vec<u8>), while Read reads and removes from the start, like a circular buffer.

6/16 use std::collections::VecDeque; use std::io::{Read, Write};
Just like Vec and String and some other collections already had, BinaryHeap, OsString, and PathBuf now also have a `try_reserve` method for fallible allocation.

Rather than panicking when out of memory, this method returns an Result::Err that you can handle manually.

7/16 pub fn try_reserve(&mut self, additional: usize) -> Result<(
The ToOwned trait now has a new (provided) method: clone_into().

In some cases, it allows for more efficient operation than the to_owned() method, because it can re-use an already existing allocation of the object you're cloning into.

8/16 fn clone_into(&self, target: &mut Self::Owned)  Uses borrowe
The old borrow checker is now completely phased out, leaving only the "non-lexical lifetimes" (NLL) borrow checker. This shouldn't change anything for you, other than some differences (hopefully improvements) in how lifetime errors are reported.

See blog.rust-lang.org/2022/08/05/nll…

9/16
If a function uses both `<T: Trait>` and `impl Trait` syntax for generics in its signature, callers are now allowed to explicitly specify the generic arguments of the first form, even if the function also uses `impl Trait` syntax.

10/16 fn write_to_file<T: Display>(path: impl AsRef<Path>, thing:
Today's release also includes a small bug fix in the language. It's technically a breaking change, but unlikely to affect any real world code.

Writing [expr; 0] (to create an array of zero elements) would not drop `expr`, but instead forget (leak) it. That has been fixed.

11/16 let s = "abc".to_string(); let a = [s; 0]; // No l
Another (very minor) breaking change to the language also involves Drop. Enums that implement Drop can no longer be casted (with the `as` operator) to an integer.

(Casting enums to integers was already restricted to enums that don't have any fields, aka C-style enums.)

12/16 pub enum Thing {     A,     B, }  impl Drop for Thing {
The documentation now includes some clarification on what `unsafe` means in edge cases like using File to write to /proc/self/mem, or using Command to spawn a debugger. These fall outside of the safety guarantees of Rust, and File::open will remain a safe function.

13/16 /proc/self/mem and similar OS features  Some platforms have
Initial support for the Nintendo 3DS has been added to the Rust standard library. It's not an officially supported platform, so no guarantees, but this should make it easier to develop Rust software for this platform.

github.com/rust-lang/rust…

14/16
In addition, the Rust compiler can now target Apple's watchOS. This is also an unsupported platform, so no guarantees, but it should now be possible to compile (no_std) Rust code for watchOS. ⌚️

(Support for `std` ships in the next release, 1.64.)

github.com/rust-lang/rust…

15/16
And that's the end of today's Rust release thread. 🏁

For a more complete list of changes in Rust 1.63, check out the release notes:

Rust: github.com/rust-lang/rust…
Cargo: github.com/rust-lang/carg…
Clippy: github.com/rust-lang/rust…

Enjoy! ✨🦀

16/16

• • •

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!

PDF

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

Jun 30
🆕🦀 Just moments ago, @rustlang 1.62.0 was released! 🎉

As usual, a thread with some of the highlights. 🧵

1/9

blog.rust-lang.org/2022/06/30/Rus…
Cargo now has 'cargo add' built-in: a (sub)command to add a crate to your Cargo.toml. It automatically looks up the latest version, and shows you the available features of the crate.

See `cargo add --help` for more details.

2/9 $ cargo add rand     Updating crates.io index       Adding r
On Linux and several BSDs, std::sync's Mutex, RwLock, and Condvar now no longer do any allocations. They used to be (heap-allocated) wrappers around pthread lock types, but have been replaced by a minimal, more efficient, futex-based implementations.

3/9

Read 9 tweets
May 16
🦀 As of Rust 1.62 (going into beta this week), std::sync::Mutex, RwLock, and Condvar no longer do any allocations on Linux. 🎉

Benchmarking locks is extremely tricky, as their performance depends heavily on the exact use case, but there are very noticable differences: A table showing before and after times of three tests.  test
std's Mutex basically used to contain a Pin<Box<pthread_mutex_t>>, where the pinned Box was only necessary because pthread_mutex_t is not guaranteed movable. The new Mutex no longer uses pthread, and instead directly uses the futex syscall, making it smaller and more efficient.
Also, the new RwLock on Linux prefers writers, which prevents writer starvation. pthread_rwlock_t prefers readers by default, to allow recursive read locking. Rust's RwLock does not make recursion guarantees, and on several platforms (including Windows) already preferred writers.
Read 4 tweets
Jan 13
🦀✨ @rustlang 1.58.0 was released just now!

blog.rust-lang.org/2022/01/13/Rus…

As usual, a thread to highlight some of the new features:

1/11
First, a feature we've all been waiting for: Format argument capturing!

let name = "world";
println!("Hello {name}!");

For now, this only works with identifiers, not with more complicated expressions. E.g. `println!("{a.f() + 10}")` does not work.

2/11

Newly stabilized in the standard library is File::options(). It's identical to OpenOptions::new(), but you don't have to import the OpenOptions type separately from the File type.

3/11 These two lines do the same thing, but the first one doesn't
Read 11 tweets
Dec 2, 2021
🦀✨ @rustlang 1.57.0 was released just moments ago!

blog.rust-lang.org/2021/12/02/Rus…

As usual, a thread to highlight some of the new features:

1/11
1. panic!() and assert!() can now be used in const fns.

Any formatting other than panic!("..") and panic!("{}", some_str) is not accepted though, because formatting is not const (yet!).

2/11 const fn f<T>() {     assert!(std::mem::size_of::<T>() < 4);error[E0080]: evaluation of constant value failed  --> src/m
2. Many functions in the standard library have been marked as #[must_use], to warn you when just calling the function without using its result is most likely a mistake.

(See the full list here: github.com/rust-lang/rust…)

3/11 let mut a: f64 = 180.0;  a.to_radians(); // Doesn't change twarning: unused return value of `core::f64::<impl f64>::to_r
Read 11 tweets
Oct 21, 2021
A few hours ago, @rustlang 1.56 was released! 🦀

This version ships with the new edition: Rust 2021! 🐊✨🎊

There's quite a few new features in the new version and edition:

1/17
Starting today, `cargo new` will use `edition = "2021"`. You can migrate your 2018 crates with `cargo fix --edition`.

These are all the edition changes:

1. `array.into_iter()` now iterates by value, instead of giving references.

(See for details.)

2/17 for (i, x) in [1, 2, 3].into_iter().enumerate() {        //
2. Closures in Rust 2021 will capture only the fields of an object you use, instead of the entire object. This should result in fewer fights with the borrow checker:

3/17 let mut x = ("a".to_string(), "b".to_str
Read 17 tweets
Sep 9, 2021
🦀 Happy new Rust! 🎆

Just now, @rustlang 1.55 was released, shipping with some small but very nice improvements.

blog.rust-lang.org/2021/09/09/Rus…

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 ...
Read 11 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

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(