
M12 Lifecycle
This is a design layer skill that helps you think through resource lifecycle questions before you write code. It maps patterns like RAII, lazy initialization, and connection pooling to concrete Rust implementations, then shows you which Layer 1 skills handle the actual code. The tables are genuinely useful: they show when Drop fires, how to choose between OnceLock and LazyLock, and why you'd pool versus create per use. It's structured around tracing up to domain constraints and down to implementation details, which matches how you actually think through these decisions. The anti-patterns section is honest about common mistakes like forgetting cleanup or reaching for lazy_static when stdlib works fine.
- skills.sh installs
- 3.5K
- GitHub stars
- 1.6K
- last updated
- Aug 21, 2026
Install
$ npx -y skills add actionbook/rust-skills --skill m12-lifecycle --agent claude-codeInstalls into .claude/skills of the current project.
Files
Resource Lifecycle
Layer 2: Design Choices
Core Question
When should this resource be created, used, and cleaned up?
Before implementing lifecycle:
- What's the resource's scope?
- Who owns the cleanup responsibility?
- What happens on error?
Lifecycle Pattern → Implementation
| Pattern | When | Implementation |
|---|---|---|
| RAII | Auto cleanup | Drop trait |
| Lazy init | Deferred creation | OnceLock, LazyLock |
| Pool | Reuse expensive resources | r2d2, deadpool |
| Guard | Scoped access | MutexGuard pattern |
| Scope | Transaction boundary | Custom struct + Drop |
Thinking Prompt
Before designing lifecycle:
-
What's the resource cost?
- Cheap → create per use
- Expensive → pool or cache
- Global → lazy singleton
-
What's the scope?
- Function-local → stack allocation
- Request-scoped → passed or extracted
- Application-wide → static or Arc
-
What about errors?
- Cleanup must happen → Drop
- Cleanup is optional → explicit close
- Cleanup can fail → Result from close
Trace Up ↑
To domain constraints (Layer 3):
Sponsors
Details
- Repository
- github.com/actionbook/rust-skills
- Categories
- Debugging, Rust, Design & UI/UX
- First seen
- May 16, 2026
More from actionbook/rust-skills
All 38- M09 Domain3.5K
- M14 Mental Model3.5K
- M11 Ecosystem3.5K
- M13 Domain Error3.5K
- Unsafe Checker3.5K
- Rust Code Navigator3.4K
- Rust Trait Explorer3.4K
- Rust Call Graph3.4K
- Rust Symbol Analyzer3.4K
- Domain Web3.4K
- Domain Cli3.4K
- Rust Learner3.3K
- Rust Skill Creator3.3K
- Rust Deps Visualizer3.2K
- Meta Cognition Parallel3.2K
- Rust Daily3.2K
- Domain Embedded3.1K
- Domain Cloud Native3K
- Domain Fintech3K
- Domain Ml3K
- Domain Iot2.9K
- Rust Router2.9K
- Core Agent Browser2.2K
- Core Dynamic Skills2K