
M12 Lifecycle
- 1.4k installs
- 1.3k repo stars
- Updated May 24, 2026
- actionbook/rust-skills
m12-lifecycle is an agent skill for design rust resource lifecycles with raii, drop, pools, and lazy initialization.
About
The m12-lifecycle skill is designed for design Rust resource lifecycles with RAII, Drop, pools, and lazy initialization. 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? Invoke when the user designs RAII, Drop, connection pools, or lazy resource initialization in Rust.
- What's the resource's scope?.
- Who owns the cleanup responsibility?.
- What happens on error?.
M12 Lifecycle by the numbers
- 1,434 all-time installs (skills.sh)
- +53 installs in the week ending Jul 28, 2026 (Skillselion tracking)
- Ranked #13 of 129 Rust skills by installs in the Skillselion catalog
- Security screen: LOW risk (skills.sh audit)
- Data as of Jul 28, 2026 (Skillselion catalog sync)
m12-lifecycle capabilities & compatibility
- Capabilities
- what's the resource's scope? · who owns the cleanup responsibility? · what happens on error?
What m12-lifecycle says it does
Use when designing resource lifecycles. Keywords: RAII, Drop, resource lifecycle, connection pool, lazy initialization, connection pool design, resource cleanup patterns, cleanup,
Use when designing resource lifecycles. Keywords: RAII, Drop, resource lifecycle, connection pool, lazy initialization, connection pool design, resource cleanup
npx skills add https://github.com/actionbook/rust-skills --skill m12-lifecycleAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 1.4k |
|---|---|
| repo stars | ★ 1.3k |
| Security audit | 3 / 3 scanners passed |
| Last updated | May 24, 2026 |
| Repository | actionbook/rust-skills ↗ |
How do I design rust resource lifecycles with raii, drop, pools, and lazy initialization?
Design Rust resource lifecycles with RAII, Drop, pools, and lazy initialization.
Who is it for?
Rust developers modeling connection pools, cleanup, and OnceCell lazy init.
Skip if: Skip for GC-managed languages without Rust ownership lifecycle concerns.
When should I use this skill?
User designs RAII, Drop, connection pools, or lazy resource initialization in Rust.
What you get
Completed m12-lifecycle workflow with documented commands, files, and expected deliverables.
- Lifecycle design decisions
- Cleanup ownership contract
- Chosen init and drop pattern
By the numbers
- Layer 2 design-choice skill in the actionbook/rust-skills series
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:
1. What's the resource cost?
- Cheap → create per use
- Expensive → pool or cache
- Global → lazy singleton
2. What's the scope?
- Function-local → stack allocation
- Request-scoped → passed or extracted
- Application-wide → static or Arc
3. 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):
"How should I manage database connections?"
↑ Ask: What's the connection cost?
↑ Check: domain-* (latency requirements)
↑ Check: Infrastructure (connection limits)| Question | Trace To | Ask |
|---|---|---|
| Connection pooling | domain-* | What's acceptable latency? |
| Resource limits | domain-* | What are infra constraints? |
| Transaction scope | domain-* | What must be atomic? |
---
Trace Down ↓
To implementation (Layer 1):
"Need automatic cleanup"
↓ m02-resource: Implement Drop
↓ m01-ownership: Clear owner for cleanup
"Need lazy initialization"
↓ m03-mutability: OnceLock for thread-safe
↓ m07-concurrency: LazyLock for sync
"Need connection pool"
↓ m07-concurrency: Thread-safe pool
↓ m02-resource: Arc for sharing---
Quick Reference
| Pattern | Type | Use Case |
|---|---|---|
| RAII | Drop trait | Auto cleanup on scope exit |
| Lazy Init | OnceLock, LazyLock | Deferred initialization |
| Pool | r2d2, deadpool | Connection reuse |
| Guard | MutexGuard | Scoped lock release |
| Scope | Custom struct | Transaction boundaries |
Lifecycle Events
| Event | Rust Mechanism |
|---|---|
| Creation | new(), Default |
| Lazy Init | OnceLock::get_or_init |
| Usage | &self, &mut self |
| Cleanup | Drop::drop() |
Pattern Templates
RAII Guard
struct FileGuard {
path: PathBuf,
_handle: File,
}
impl Drop for FileGuard {
fn drop(&mut self) {
// Cleanup: remove temp file
let _ = std::fs::remove_file(&self.path);
}
}Lazy Singleton
use std::sync::OnceLock;
static CONFIG: OnceLock<Config> = OnceLock::new();
fn get_config() -> &'static Config {
CONFIG.get_or_init(|| {
Config::load().expect("config required")
})
}---
Common Errors
| Error | Cause | Fix |
|---|---|---|
| Resource leak | Forgot Drop | Implement Drop or RAII wrapper |
| Double free | Manual memory | Let Rust handle |
| Use after drop | Dangling reference | Check lifetimes |
| E0509 move out of Drop | Moving owned field | Option::take() |
| Pool exhaustion | Not returned | Ensure Drop returns |
---
Anti-Patterns
| Anti-Pattern | Why Bad | Better |
|---|---|---|
| Manual cleanup | Easy to forget | RAII/Drop |
lazy_static! | External dep | std::sync::OnceLock |
| Global mutable state | Thread unsafety | OnceLock or proper sync |
| Forget to close | Resource leak | Drop impl |
---
Related Skills
| When | See |
|---|---|
| Smart pointers | m02-resource |
| Thread-safe init | m07-concurrency |
| Domain scopes | m09-domain |
| Error in cleanup | m06-error-handling |
Related skills
Forks & variants (1)
M12 Lifecycle has 1 known copy in the catalog totaling 780 installs. They canonicalize to this original listing.
- zhanghandong - 780 installs
How it compares
Pick m12-lifecycle over syntax-focused Rust skills when the hard problem is when resources live and who cleans them up.
FAQ
What does m12-lifecycle do?
Design Rust resource lifecycles with RAII, Drop, pools, and lazy initialization.
When should I use m12-lifecycle?
User designs RAII, Drop, connection pools, or lazy resource initialization in Rust.
Is m12-lifecycle safe to install?
Review the Security Audits panel on this page before installing in production.