What it does. Rust design patterns for RTK. Newtype, Builder, RAII, Trait Objects, State Machine. Applied to CLI filter modules. Use when designing new modules or refactoring existing ones.
RTK Rust Design Patterns
Patterns that apply to RTK's filter module architecture. Focused on CLI tool patterns, not web/service patterns.
Pattern 1: Newtype (Type Safety)
Use when: wrapping primitive types to prevent misuse (command names, paths, token counts).
// Without Newtype — easy to mix up
fn track(input_tokens: usize, output_tokens: usize) { ... }
track(output_tokens, input_tokens); // Silent bug!
// With Newtype — compile error on swap
pub struct InputTokens(pub usize);
pub struct OutputTokens(pub usize);
fn track(input: InputTokens, output: OutputTokens) { ...
**Install**
```bash
npx skills add rtk-ai/rtk --skill design-patterns
Or copy the skill folder manually:
git clone https://github.com/rtk-ai/rtk.git
cp -r rtk/.claude/skills/design-patterns/ ~/.claude/skills/design-patterns
Source: rtk-ai/rtk — 84,246 stars, Apache-2.0, verified 2026-10-22.