Notes for Zero to Production in Rust

Zero to Production in Rust bills itself as "the ideal starting point for your journey as a Rust backend developer."

I have used Rust as hobbyist, mostly in the context of working on Advent of Code problems. I also listen to Chris Krycho's New Rustacean podcast which is a great introduction to the language (and certainly the best in the audio-only category).

Zero to Production seems like an obvious next step in my Rust learning journy, and I wanted to use this site to capture my thought and notes along the way.

Zero2Prod is a paid book, so I will not be excerpting any material from the book, but I will bring in code from the public Github Repo, which is MIT licensed.

I will not be following the book exactly. Notably, I will be diverting from using Actix-Web in favor of Axum as the web server. I will call out additional changes I make along the way.

These notes will be exist in the zero2prod project directory as I work on it. I will attempt to keep my notes and the proejct progress in sync.

You can find the Repository for this project on Github.

Onwards to Chapter 1 - Getting Started!

Chapter 1 - Getting Started

Tools

This chapter goes over installing the Rust toolchain (Rustup), as well as goes over how to intialize a project using cargo new.

There is a recommendation for using IntelliJ with the Rust plugin. Since the latest version of the book, JetBrains has announced Rust Rover, a dedicated Rust IDE, so I imagine that would be the new recommendation.

I will be using VSCode with the rust-analyzer add-on.

Linking

Section 1.4.1 gave tips for setting up a faster linker. I added the configuration to .cargo/config.toml, making sure I installed llvm and exported the flags recommended by brew install llvm.

# On Windows
# ```
# cargo install -f cargo-binutils
# rustup component add llvm-tools-preview
# ```
[target.x86_64-pc-windows-msvc]
rustflags = ["-C", "link-arg=-fuse-ld=lld"]
[target.x86_64-pc-windows-gnu]
rustflags = ["-C", "link-arg=-fuse-ld=lld"]
# On Linux:
# - Ubuntu, `sudo apt-get install lld clang`
# - Arch, `sudo pacman -S lld clang`
[target.x86_64-unknown-linux-gnu]
rustflags = ["-C", "linker=clang", "-C", "link-arg=-fuse-ld=lld"]
# On MacOS, `brew install llvm` and follow steps in `brew info llvm`
[target.x86_64-apple-darwin]
rustflags = ["-C", "link-arg=-fuse-ld=lld"]

Development Loop

Install cargo install cargo-watch and then

cargo watch -x check -x test -x run

CI

The recommended Github actions CI is found on Github

And thats it for chapter 1, Onward to Chapter 2!

Chapter 2 - Building an Email Newsletter

Chapter 2 goes thorugh the goals of the book and the project we will be building: an Email Newsletter.

2.2 Goes over the concept of user stories, and gives us the driving user story for the newsletter:

  • As a blog visitor, I want to subscribe to the newsletter, So that I can receive email updates when new content is published on the blog;
  • As the blog author, I want to send an email to all my subscribers, So that I can notify them when new content is published.

2.3 Covers working in iterations. My assumption is that these will correspond to chapters, or perhaps sub-chapters, but that remains to be seen. Each interation will be properly documeted and tested and fully functional for production, even if the functionality is tiny.

In Chapter 3 we start building!

Chapter 3 - Sign Up A New Subscriber

TODO