Project 5: Build a String Interning System
A string interner that stores unique strings once and returns references with tied lifetimes, demonstrating lifetime annotations in practice.
Quick Reference
| Attribute | Value |
|---|---|
| Primary Language | Rust |
| Alternative Languages | None |
| Difficulty | Level 4: Expert |
| Time Estimate | 1-2 weeks |
| Knowledge Area | Lifetimes / String Optimization |
| Tooling | Rust, HashMap |
| Prerequisites | Projects 1-4, comfort with lifetimes |
What You Will Build
A string interner that stores unique strings once and returns references with tied lifetimes, demonstrating lifetime annotations in practice.
Why It Matters
This project builds core skills that appear repeatedly in real-world systems and tooling.
Core Challenges
- Returning references with explicit lifetimes → maps to lifetime annotations
'a - Storing heterogeneous string types → maps to
Stringvs&strtradeoffs - Ensuring uniqueness → maps to HashMap with owned keys but borrowed returns
- Handling self-referential structures → maps to limitations of safe Rust
Key Concepts
- Lifetimes: “The Rust Programming Language” Chapter 10.3
- Lifetime Annotations: “Programming Rust” Chapter 5
- String Interning: “Crafting Interpreters” Chapter 20 (concept)
- Variance: “The Rustonomicon” - Subtyping and Variance
Real-World Outcome
Deliver a working demo with observable output that proves the feature is correct.
Implementation Guide
- Reproduce the simplest happy-path scenario.
- Build the smallest working version of the core feature.
- Add input validation and error handling.
- Add instrumentation/logging to confirm behavior.
- Refactor into clean modules with tests.
Milestones
- Milestone 1: Minimal working program that runs end-to-end.
- Milestone 2: Correct outputs for typical inputs.
- Milestone 3: Robust handling of edge cases.
- Milestone 4: Clean structure and documented usage.
Validation Checklist
- Output matches the real-world outcome example
- Handles invalid inputs safely
- Provides clear errors and exit codes
- Repeatable results across runs
References
- Main guide:
RUST_BORROW_CHECKER_LIFETIME_PHILOSOPHY.md - “Programming Rust” Chapter 5