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

Jan 13, 11 tweets

🦀✨ @rustlang 1.58.0 was released just now!…

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


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.


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.


Option and Result now have an unsafe unwrap_unchecked() function. If you're absolutely sure that the Option contains a Some, or the Result contains an Ok, you can use these to unwrap the value while skipping any checks. (Getting this wrong means undefined behaviour though!)


Path and Metadata now have an is_symlink() method. This saves some typing, as previously this had to be done with std::fs::symlink_metadata(path) followed by metadata.file_type().is_symlink().


In Rust 1.57, many library functions got the #[must_use] attribute to prevent subtle mistakes. With Rust 1.58, this effort is now completed, and all functions that should have #[must_use] according to the accepted guidelines now have that attribute.


The `Command` api now no longer searches the current working directory on Windows, to match the behaviour on other platforms. This will prevent problems like CVE-2021-3013:…


Many file operations like File::open(), fs::create_dir(), etc. now all work with long paths on Windows. The paths are automatically canonicalized and prefixed by \\?\, which is how extended-length paths are expressed on Windows.


Const evaluation got a bit more powerful again. You can now dereference pointers in const context. Only *const though, not *mut.


And the last thing I want to highlight in this thread:

Rustdoc now shows methods from all recursive Deref implementations, instead of only the outermost one. So if your type is Deref<Target = String>, it now not only shows the String methods, but also all the str methods.


And that's the end of today's thread!

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


Enjoy! ✨🦀


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