Abstract
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.
This doesn't need to be this way. Rust is an elegant language, and it has many means to reduce clutter. This is what we will focus on in this workshop. We take a real-world program and refactor it piece by piece. In doing so, we will learn about the following topics:
- Effective use of syntax and built-in methods
- Error handling, error boundaries, and happy path programming
- Abstracting with traits
- Possibilities for polymorphism: Generics, trait objects, enums
- How type inference for `Default::default()`, `Into::into()` works - Working with Iterators
- Designing for Ownership
As a last step, we will write a new feature for both the original and the refactored version. The comparison will amaze you!