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-code

Installs 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

PatternWhenImplementation
RAIIAuto cleanupDrop trait
Lazy initDeferred creationOnceLock, LazyLock
PoolReuse expensive resourcesr2d2, deadpool
GuardScoped accessMutexGuard pattern
ScopeTransaction boundaryCustom 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):

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

Recommended

More Debugging
1giuseppe-trisciuoglio avatarwiremock-standalone-dockergiuseppe-trisciuoglio/developer-kitProvides patterns and configurations for running WireMock as a standalone Docker container. Generates mock HTTP endpoints, creates stub mappings for testing, va3.5Kskills.sh installs
2majidmanzarpour avatarthreejs-qa-releasemajidmanzarpour/threejs-game-skillsVerify and release Three.js browser games. Combines playtest QA, automated bot playtests, mobile/responsive checks, production builds, preview verification, sta3.5Kskills.sh installs
3avdlee avatarspm-build-analysisavdlee/xcode-build-optimization-agent-skillAnalyze Swift Package Manager dependencies, package plugins, module variants, and CI-oriented build overhead that slow Xcode builds. Use when a developer suspec3.5Kskills.sh installs
4avdlee avatarxcode-build-benchmarkavdlee/xcode-build-optimization-agent-skillBenchmark Xcode clean and incremental builds with repeatable inputs, timing summaries, and timestamped `.build-benchmark/` artifacts. Use when a developer wants3.5Kskills.sh installs
5kkkkhazix avatarneat-freakkkkkhazix/khazix-skillsKnowledge and governance closeout: reconcile project docs, rule files (CLAUDE.md/AGENTS.md), authorized agent memory, and workspace residue with what the code a3.5Kskills.sh installs
6minimax-ai avatarfullstack-devminimax-ai/skillsFull-stack backend architecture and frontend-backend integration guide. TRIGGER when: building a full-stack app, creating REST API with frontend, scaffolding ba3.5Kskills.sh installs