The Rustacean Station Podcast

This Week in Rust - Issue 344

Episode Page with Show Notes

Nell Shamrell-Harrington: Hello everyone and welcome to This Week in Rust! As always, I’m Nell Shamrell-Harrington, lead editor of the This Week in Rust newsletter. I’m also Sr. Staff Research Engineer on the Rust team at Mozilla.

As a reminder, if you write or read a great article on Rust, if you have a Rust job opportunity, or if you have a call for participation for the Rust community, please submit it to This Week in Rust twitter account or the This Week in Rust GitHub repo. We depend on you to help us make each issue valuable to the entire Rust community.

This Week in Rust is published on Tuesdays, which means I usually record these episodes on Monday night. If you’d like your article to potentially be included in the podcast, please be sure to submit it on or before Monday.

Now let’s take a look at some featured stories from issue number 344.

The Rust release team published a post on the official Rust blog announcing Rust 1.44.1. This new version addresses several tool regressions in Cargo, Clippy, and Rustfmt that were introduced in the 1.44.0 release.

One of my personal favorite articles in this week’s issue is “Writing Non-Trivial Macros in Rust” by Michael F. Bryan. As they mention at the start of the article, Rust Macros are trivial to use for simple search/replace style operations or straightforward trait implementations for a large number of types. However, once you get beyond these, “the difficulty tends to go through the roof…”. This post will take you through implementing an Incremental TT Muncher. As the Little Book of Rust Macros defines it, quote “an Incremental TT Muncher is a recursive macro that works by incrementally processing its input one step at a time. At each step, it matches and removes (munches) some sequence of tokens from the start of its input, generates some intermediate input, then recurses on the input tail.” unquote. In this article, you will learn how to adapt a macro to match the function signature at the start of an input stream, then recurse on the rest of the stream. Definitely check out the post for the full examples and even more information on advanced Rust macros.

The next story I want to highlight is “How to Design for Panic Resilience in Rust” by Luke Wilson. In the author’s own words, “If you consider your software as a car driving at about 60 miles per hour, a panic is like hitting a brick wall.” Most of the time, rather than panicking, code should provide clear feedback and prevent halting execution. Wilson makes this clear through three sections: when to panic, handling errors, and error handling in a library. This post is a great source of information on understanding how to handle errors in your Rust code.

One of the joys of editing This Week in Rust is seeing series of posts as they progress over time. This week’s issue features several posts that are a part of an ongoing series.

Tour of Rust, a step by step guide through the features of the Rust programming language, has published Chapter 8 on Smart Pointers. This chapter focuses on demystifying smart pointers. It explores these data structures that allow us to interact with the lowest level of memory. You will learn about raw pointers, dereferencing, using the dot operator to access the fields and methods of a reference, types of smart pointers including Reference Counting, RefCell, Mutexes, Arc, combining smart pointers, and more.

Stephen Marz has published Chapter 11 of a series on learning how to write an Operating System targeting the RISC-V architecture in Rust. This chapter covers the ELF file format or executable and linkable format. Quote “In Linux, the only file type that really matters is ELF. Everything else is left up to whatever helper program it needs.” This chapter will teach you how to create an ELF file and use it to load a process from the disk and run it.

Amos Wenger has published part 13 of their series titled “Making our Own Executable Packer.” This series also focuses on ELF files quote “what they are, what they can do, what does the dynamic linker do to them, and how we can do it ourselves” unquote. This chapter is on thread level storage and is a very thorough introduction to registers, how the kernel schedules and switches between processes, threads, intel chips, type states, and much more.

Luca Palmieri has published Chapter 2 of the “Zero to Production” series. This series is focused on the challenges of writing cloud-native applications in a team of four or five engineers with different levels of experience and proficiency. This chapter covers problem-based learning, capturing requirements, working in iterations, and more.

Several Rust videos were brought to our attention this week.

The first is a new addition to the Crust of Rust series from Jon Gjengset. To quote a YouTube commenter on these videos “These are really great, and they fill the “intermediate” gap in Rust tutorials, which is very valuable!” The latest episode covers smart pointers and interior mutability by re-implementing the Cell, RefCell, and Rc types from the standard library. As part of that, it also covers when those types are useful, how they work, and the equivalent thread-safe versions of these types.

The University of Illinois at Urbana Champaign is publishing lectures from its CS 196 course on YouTube, including several on Rust. These Rust focused lessons include content on Shared State Concurrency, Mutexes, Threads, Functional Programming, Closures, Strings, Slicing, and Structs, and much more.

Ryan Levick has published a new Rust stream on “The Guard Pattern and Interior Mutability.” In their words it is “A stream meant for “advanced beginners” of Rust on the “guard pattern” a common API construct for wrapping items in order to do things when those items are no longer used. In this video we implement a simple resource pool that allows users to get items from a pool and returns those items to the pool when they’re no longer needed”.

Finally for videos, Felix Klock, also a member of the Rust team at Mozilla, recently held an Ask Me Anything session at the PLDI London Conference. He answers questions about his background with Rust, garbage collection and why Rust doesn’t need it, why Rust has been successful, Rust interoperability with other languages, unsafe Rust, and more.

There are many more news stories and blog posts in this week’s issue of This Week in Rust - make sure to check out the newsletter for all of them.

Let’s move onto the Call for Participation section.

The GitUI project is looking for contributors. GitUI is a blazing fast terminal client for git written in Rust. The maintainers have marked several issues as good first ones and have had good experiences mentoring Rust newcomers.

Additionally, the Ruma project has an issue labeled as “Easy” and they are looking for new contributors to pick up the issue. Ruma is a set of Rust library crates for working with the Matrix online communication protocol and is a great way to get involved with Rust.

Next, let’s discuss this week in RFCs.

One new RFC was proposed titled “C unwind ABI.”

Unwinding is what happens when a program you are running throws an exception. When the exception is thrown, the runtime for the program will unwind the stack and essentially traverse backward through it, calling any clean up or error recovery code.

Rust does not implement exceptions the way languages like C++ do, but it does support unwinding under two conditions. When rust code panics, it will unwind the stack. Also when Rust is interfacing with another programming language that does implement exceptions — such as C++ — it can call functions in that language to unwind the stack.

Currently, when foreign code — that means code not written in Rust — calls Rust code and the Rust code panics, the foreign code cannot unwind that Rust panic. Likewise, when Rust calls foreign code and that code throws an exception, Rust cannot unwind what happened in that code.

This RFC seeks to change this by defining a new ABI string — an addition to the current ABI. An ABI is an application binary interface — it’s a way for two compiled binaries to interact with each other. The ABI string defined by this RFC makes it safe to unwind C++ frames with a Rust panic and unwind Rust frames with a C++ exception.

For more details and examples, make sure to read the full RFC.

No RFCs were approved this week, and no RFCs are currently in Final Comment Period.

However, several tracking issues and pull requests are in final comment period. All of them are current labeled as disposition: merge. Let’s go through a few of them.

The first of these adds an implementation that allows a String to be created from a Char type.

Another is a pull request that stabilizes the leading_trailing_ones feature and will make it a part of Rust 1.46.0 The leading_trailing_ones feature is implemented on an unsized integer, or usize, type. It returns the number of trailing ones in the binary representation of itself.

Another pull request uses a macro to add the TryFrom{int} trait for non-zero ints. This pull request also includes some great examples of how to write tests, especially for conversions between data types

One more pull request in final comment period stabilizes the track_caller feature. When a call to the expect or unwrap method on an Option or Result type fails, it returns a panic. However, it can be hard to figure out exactly where in the code the panic is happening. The track_caller feature makes it so that these panics return a much more helpful message, including where the panic originated in the programmer’s code. This pull request stabilizes the use of track_caller everywhere, including in traits and extern blocks.

Check out the RFC section of this week’s issue for even more tracking issues and pull requests that are in final comment period.

As for events, we continue to see most meetups being held online due to the COVID-19 pandemic. No matter where you are in the world, you have the chance to tune into online meetups from Wroclaw, Poland, Edinburgh, Scotland, Berlin, Germany, and Johannesburg, South Africa.

There are also some in person meetups coming up in Dallas, TX, Indianapolis, IN, and Auckland, New Zealand.

And that’s all for this episode of the This Week in Rust podcast. Make sure to read the newsletter for even more great Rust content.

This Week in Rust is edited by myself, Andre Bogus, and Colton Donnelly. This week’s contributors included, using their GitHub usernames, Nnethercote, Rjnn, LukeMathWalker, Michael-F-Bryan, Hmbl, Extrawurst, Fleabitdev, and gterzian.

Thank you so much to everyone who contributes to This Week in Rust, you are the reason we can get this newsletter out and I can do this podcast every week!

I will be back next week bringing you more of the wonderful news from the wonderful world of Rust. Until then, please take care.