Refactoring Rust

Instructor: Stefan Baumgartner

Rust is undeniably syntax-heavy. There’s a lot of intent to express, and Rust wants you to be explicit. All the extra effort can result in bloated code and hard-to-use APIs. Especially features like the trait system, error handling, and ownership add another layer of complexity that can’t be controlled by the usual refactoring techniques we have been teaching for the last decades.

In this hands-on workshop, we refactor a Rust program that has just left the prototyping stage into code that is a delight to read and follow, easy to use, easy to maintain, and that plays along nicely with the ecosystem. We take a real-world program and refactor it piece by piece. As a last step, we will write a new feature for both the original and the refactored version. The comparison will amaze you!

Prerequisites / target audience

This workshop is designed for developers who are working on Rust codebases already and are looking to level up their skills.

Topics

Technological prerequisites

Rustup provides you with all the software to compile and run Rust applications, e.g.

  1. Cargo - build tool and package manager
  2. rustfmt - Auto-formatting tool for Rust code
  3. clippy - Linting for common mistakes

and many more. Rustup also allows you to install different compile targets and multiple toolchains, as well as keeping your toolchains up to date.

After installing, you should have a set of new command line tools available.

Verify your Rust installation:

  1. Open a Terminal/Shell/Command Line of your choice
  2. Check out this repo
  3. Navigate to this repository
  4. Enter
$ cargo build
  1. Open your browser at https://localhost:3000

During the workshop, we will use Visual Studio Code as editor. It’s free, fast and very extensible. Making yourself familiar with VS Code is highly recommended.

However, working with VS Code is not required. If you have a preferred editor with Rust support you’re more productive with, please feel free to use whatever you like. What we highyly recommend though, is checking if your editor has support for Rust analyzer.

To work effeciently, please install a couple of extensions that help you developing Rust. Note: Please don’t install the recommendend Rust extension. It’s outdated and the community decided to move to other tools. You can search and install VS Code extensions through the menu on the side

We recommend the following extensions:

Additionally, we will share a Github project with workshop materials. This information will be provided closer to the workshop date.


Stefan Baumgartner

For location and schedule visit our Workshops page