Refactoring in Rust
summary
A weekend-prototype Rust web app using axum and the image crate gets refactored into clear, testable pieces: unwraps and expects are removed in favor of ? propagation; a KVError struct holding an axum StatusCode implements From for poison and image errors and IntoResponse; a TryFrom<DynamicImage> -> ImageResponse hides buffer and PNG conversion; stored values become an enum StoredItem and a database trait lets the hashmap swap for a real DB, reducing grayscale to a one-line call and enabling thumbnails.
AI-written summary · about
chapters (11)
- 0:00Introduction
- 1:27Refactoring scenario setup
- 2:50Messy codebase examination
- 7:28Error handling with custom types
- 13:05Type-driven refactoring for images
- 18:45Type-driven design philosophy
- 19:06Refactoring storage with enums
- 23:45Final refactored code
- 27:15Refactoring improves efficiency
- 28:20Trait implementation scene
- 29:45Q&A
related talks
49mThe Eternal Sunshine of the Spotless Programming Language
35mBuilding composable web services with Axum
36mWeb development with Rust, is it ready? Is it even useful?
30mTrials, traits, and tribulations
28mRust Irgendwie, Irgendwo, Irgendwann
49mThe State of Rust Ul
42mBuilding a Web Application with Rust
26mTherapeutic Refactoring
