The m12-lifecycle skill guides developers through designing resource lifecycles in Rust by answering when resources should be created, used, and cleaned up. It covers patterns like RAII, lazy initialization, connection pooling, and scope guards, tracing decisions from domain constraints down to implementation details using ownership and the Drop trait. This skill is for Rust developers designing systems that manage expensive resources like database connections, helping them choose appropriate patterns based on resource cost, scope, and error handling requirements.

skills.sh installs
764
GitHub stars
1.3K
last updated
Jul 14, 2026

Install

$ npx -y skills add zhanghandong/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/zhanghandong/rust-skills
Category
Rust

More from zhanghandong/rust-skills

All 34

Recommended

More Rust
1zhanghandong avatarm14-mental-modelzhanghandong/rust-skillsm14 mental model751skills.sh installs
2zhanghandong avatarm09-domainzhanghandong/rust-skillsm09 domain750skills.sh installs
3zhanghandong avatarm11-ecosystemzhanghandong/rust-skillsm11 ecosystem747skills.sh installs
4zhanghandong avatarmeta-cognition-parallelzhanghandong/rust-skillsmeta cognition parallel635skills.sh installs
5zhanghandong avatardomain-embeddedzhanghandong/rust-skillsdomain embedded625skills.sh installs
6mohitmishra786 avatarrustc-basicsmohitmishra786/low-level-dev-skillsRust compiler skill for systems programming. Use when selecting RUSTFLAGS, configuring Cargo profiles, tuning release builds, reading assembly or MIR output, un567skills.sh installs