Claude Code Rust skill for enforcing type invariants in try_new
Centralize the valid range for Rust configuration values in a canonical constructor and return a named error for an invalid input.
中文Install in Claude Code
Use Claude Code in a Rust workspace with a new configuration type and a defined valid range. Prepare lightweight unit tests.
- Review `.claude/skills/validate-in-constructor/SKILL.md` and its requirements at the pinned GitHub commit.
- Create `.claude/skills/validate-in-constructor/` in your project and save the reviewed file as `.claude/skills/validate-in-constructor/SKILL.md`.
- Start Claude Code from that project's root, then select `/validate-in-constructor` in the slash menu.
Example task
Use a display row count constrained to 1 through 24. Keep the field private, construct using try_new, and test accepted and out-of-range values.
`DisplayRows::try_new(0)` · `DisplayRows::try_new(12)` · `1..=24`What to check
`DisplayRows::try_new(12)` creates a `12`-row configuration. The input `0` returns `InvalidRowCount`, and callers construct values through the validator.
Original SKILL.md on GitHub · Updated
Frequently asked question
Should other construction paths copy the validation?
Delegate them to the canonical validating constructor to keep the range consistent across entry points.