# m12-lifecycle

Helps design Rust resource lifecycles, from creation and scope to cleanup and error handling. Useful for connections, transactions, guards, and lazy initialization.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 3300 installs · ★ 1545
- Author: actionbook
- License: not stated · policy=link-only · description only; the file stays with the author
- Source: https://github.com/actionbook/rust-skills/tree/HEAD/skills/m12-lifecycle/SKILL.md
- Updated: 2026-08-23
- HTML: https://affpapa.org/en/nevibecode/skills/m12-lifecycle

## What it does

This skill helps choose how a Rust resource should be created, owned, used, and cleaned up. It maps RAII to `Drop`, deferred creation to `OnceLock` and `LazyLock`, expensive resource reuse to `r2d2` or `deadpool`, and scoped access to the `MutexGuard` pattern.

It includes design questions about scope and cleanup ownership, lifecycle event tables, RAII guard and lazy singleton templates, plus common failures such as leaks, double free, `E0509`, and pool exhaustion. Related paths connect the decisions to `m02-resource`, `m03-mutability`, `m06-error-handling`, and `m07-concurrency`.

When cleanup itself can fail, the skill points to an explicit `close` that returns `Result`, so that case deserves a separate design check before relying on `Drop`. For cleanup at scope exit, it uses `Drop` with an RAII wrapper.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add actionbook/rust-skills --skill m12-lifecycle -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/m12-lifecycle/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/m12-lifecycle/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add actionbook/rust-skills --skill m12-lifecycle -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/m12-lifecycle/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add actionbook/rust-skills --skill m12-lifecycle -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/m12-lifecycle/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install actionbook/rust-skills m12-lifecycle
```

2. **Manually: put the files in place**
- File: `.github/skills/m12-lifecycle/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add actionbook/rust-skills --skill m12-lifecycle -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/actionbook/rust-skills --path skills/m12-lifecycle
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/m12-lifecycle/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add actionbook/rust-skills --skill m12-lifecycle -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/actionbook/rust-skills/tree/HEAD/skills/m12-lifecycle/SKILL.md

## When to use it
- choose a resource scope
- design cleanup for error paths
- set up lazy initialization
- select a pool for costly connections
- trace why a resource pool is exhausted

## Example prompts
- Design a Rust lifecycle for database connections, covering creation cost, scope, ownership, and cleanup on errors.
- Compare `Drop`, `OnceLock`, `LazyLock`, and a connection pool for this resource, then recommend an implementation.
- Inspect this resource leak and show where `Drop` should return the resource to the pool.

## Similar
- [memory-safety-patterns](https://affpapa.org/en/nevibecode/skills/memory-safety-patterns.md) — skill · 11746 installs
- [cpp-pro](https://affpapa.org/en/nevibecode/agents/cpp-pro.md) — subagent · 781 installs
- [maui-app-lifecycle](https://affpapa.org/en/nevibecode/skills/maui-app-lifecycle.md) — skill · 3300 installs
- [mongodb-connection](https://affpapa.org/en/nevibecode/skills/mongodb-connection.md) — skill · 5200 installs
- [redis-connections](https://affpapa.org/en/nevibecode/skills/redis-connections.md) — skill · 2800 installs
- [asc-build-lifecycle](https://affpapa.org/en/nevibecode/skills/asc-build-lifecycle.md) — skill · 7200 installs

From the same set: [actionbook/rust-skills](https://affpapa.org/en/nevibecode/by/actionbook/rust-skills.md) — 35 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
