
M12 Lifecycle
Rust resource lifecycle guide covering RAII, lazy init, pooling, guards, and transaction scopes.
- skills.sh installs
- 3.6K
- GitHub stars
- 1.6K
- last updated
- Aug 21, 2026
What it does
- Covers the lifecycle decision flow: resource cost, scope, and error-time cleanup, with pattern-to-implementation mappings
- Includes a pattern table (RAII, lazy init, pool, guard, scope) and templates for a
Drop-based file guard and aOnceLocksingleton - Lists common errors such as leaks, E0509 move-out-of-Drop fixes via
Option::take(), and pool exhaustion from unreturned connections - Designed for Rust developers deciding when resources are created, shared, and cleaned up, and flags
lazy_static!in favor ofstd::sync::OnceLock
Install
$ npx -y skills add actionbook/rust-skills --skill m12-lifecycle -yInstalls into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.
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):
Details
- Repository
- github.com/actionbook/rust-skills
- Categories
- Rust, Backend & APIs
- First seen
- May 16, 2026
More from actionbook/rust-skills
All 38- M09 Domain3.6K
- M14 Mental Model3.6K
- M13 Domain Error3.6K
- M11 Ecosystem3.6K
- Unsafe Checker3.6K
- Rust Code Navigator3.6K
- Rust Trait Explorer3.5K
- Rust Call Graph3.5K
- Rust Symbol Analyzer3.5K
- Domain Web3.5K
- Domain Cli3.5K
- Rust Learner3.4K
- Rust Skill Creator3.4K
- Rust Deps Visualizer3.3K
- Meta Cognition Parallel3.3K
- Rust Daily3.3K
- Domain Embedded3.2K
- Domain Cloud Native3.2K
- Domain Fintech3.1K
- Domain Ml3.1K
- Domain Iot3K
- Rust Router3K
- Core Agent Browser2.3K
- Core Dynamic Skills2.1K
Similar to M12 Lifecycle
More Rust
m01-ownershipactionbook/rust-skills3.7K installsRust ownership and lifetime error guide that maps compiler codes to design questions before quick fixes.
m02-resourceactionbook/rust-skills3.7K installsChoosing Rust smart pointers by ownership model, thread context, and reference cycles, with a decision flowchart.
memory-safety-patternswshobson/agents12.3K installsCross-language memory-safety patterns covering RAII, ownership, smart pointers, and resource management for Rust, C++, and C.
rust-systems-programmingmanutej/luxor-claude-marketplace489 installsComplete Rust guide covering ownership, borrowing, concurrency, async, and unsafe code for memory-safe systems work.
rust-patternsaffaan-m/ecc6.7K installsIdiomatic Rust patterns for ownership, error handling, enums, traits, iterators, and concurrency in production code.