design-patterns
This skill covers seven Rust design patterns applied to RTK's CLI filter architecture, from type-safe wrappers and configuration builders to stateful parsers and resource management. Each pattern includes practical examples showing when to use it, when to skip it, and how it fits RTK's single-threaded, zero-overhead design philosophy.
design-patterns teaches Rust patterns like Newtype, Builder, and State Machine for structuring RTK's CLI filter modules.
AI-generated summary based on this skill's SKILL.md
Install
rtk-ai/rtk/design-patterns · repository language: Rust
git clone https://github.com/rtk-ai/rtk
cp -r rtk/.claude/skills/design-patterns ~/.claude/skills/design-patternsnpx skillfed install rtk-ai/rtk/design-patternsFrequently asked questions
AI-generated answers based on this skill's SKILL.md and metadata
What rust design patterns for CLI tools does design-patterns cover?
design-patterns teaches seven Rust design patterns applied to RTK's CLI filter architecture. It covers type-safe wrappers, configuration builders, stateful parsers, and resource management patterns. Each pattern includes practical examples showing when to use it, when to skip it, and how it fits RTK's single-threaded, zero-overhead design philosophy.
How do I choose the right pattern for a new module or refactoring task?
design-patterns helps you select appropriate patterns by showing real use cases within RTK's codebase. The skill explains when to apply Newtype for type safety, Builder for complex configuration, State Machine for parsing workflows, and other patterns. It also covers anti-patterns to avoid and over-engineering risks specific to RTK's architecture.
When should I use the Newtype pattern in Rust?
design-patterns explains that Newtype provides type-safe wrappers without runtime overhead. Use it when you need to distinguish semantically different values of the same underlying type—for example, wrapping a String as a FilterName to prevent accidental mixing with other strings. It's zero-cost and catches errors at compile time.
What is the builder pattern and when does design-patterns recommend it?
design-patterns covers Builder pattern for constructing complex objects with many optional fields. It's ideal for CLI filter configuration where you want fluent, readable setup code. The skill shows when Builder adds clarity versus when simpler constructors suffice, helping you avoid over-engineering in RTK's single-threaded context.
How does design-patterns explain state machine pattern for parsing?
design-patterns demonstrates state machine patterns for stateful parsing workflows common in CLI filters. It shows how to model parser states as enum variants and transitions as method calls, making parsing logic explicit and type-safe. Examples illustrate resource cleanup and error handling within state transitions.
What RAII and resource management patterns does design-patterns teach?
design-patterns covers RAII (Resource Acquisition Is Initialization) for safe resource cleanup in Rust. It explains how Drop traits and scope-based cleanup eliminate manual resource management bugs. The skill shows practical examples of file handles, buffers, and temporary allocations in RTK's filter modules, emphasizing zero-overhead resource safety.
SKILL.md
rendered from the published skill — quoted content, verbatim
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) { ... }
track(OutputTokens(100), InputTokens(400)); // Compile error ✅
```rust // Practical RTK example: command name validation pub struct
(truncated - see the full file via the links below)
Read as markdown · JSON record · Browse the source repository
File tree — 1 file
.claude/skills/design-patterns/SKILL.md