Using Generics Effectively
summary
The uploader shows code from Naughty, a terminal that handles Unicode, double-width characters and inline images, and reports that typical apps have about a 1:20 trait to type ratio while Naughty sits at a 1:8 ratio (90 types, 12 traits versus Cargo’s ~200 types and 10 traits). A huge enum-based write method balloons to over a hundred lines; refactoring to a writer trait makes the top-level write one line, isolates mutation, and enables lightweight mock implementations for clean unit tests.
AI-written summary · about
chapters (11)
- 0:00Introduction
- 1:40Traits in Rust
- 3:22Traits in apps vs libraries
- 5:50Polymorphism traits vs enums
- 7:11Refactor enum to trait
- 12:25Traits with one impl
- 14:50Abstraction beyond reuse
- 16:57Decouple modules with traits
- 19:04Mocking with traits
- 20:51Traits vs enums
- 22:12Patterns in Rust
related talks
25mType System Tips for the Real World
49mThe Eternal Sunshine of the Spotless Programming Language
15mSupercharging Your Code With Five Little-Known Attributes
59mTemplate Metaprogramming: Type Traits (part 2 of 2)
19mType Theory for the Working Rustacean
52mStrong types for strong interfaces
26mMaking life easier with Derive and other tools
43mHow to stop fighting with coherence and star writing context-generic trait impls
