m12-lifecycle

Installation
Summary

Design resource creation, cleanup, and scope using RAII, lazy initialization, and pooling patterns.

  • Covers five lifecycle patterns: RAII with Drop trait, lazy initialization via OnceLock/LazyLock, connection pooling with r2d2/deadpool, guard-based scoped access, and transaction scope boundaries
  • Includes decision framework for resource cost, scope determination, and error handling during cleanup
  • Provides pattern templates for RAII guards and lazy singletons, plus common errors and anti-patterns to avoid
  • Traces connections to ownership models (Layer 1) and domain constraints (Layer 3) for integrated design
SKILL.md

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
Related skills

More from zhanghandong/rust-skills

Installs
678
GitHub Stars
1.1K
First Seen
Jan 20, 2026