Claude Code Rust skill for accessor-based struct field encapsulation
Keep fields private in a new Rust library type and expose a stable borrowed accessor for callers.
中文Install in Claude Code
Open Claude Code in a Rust library checkout. Review public API compatibility needs and use a new, unpublished type for this exercise.
- Review `.claude/skills/private-fields-with-accessors/SKILL.md` and its requirements at the pinned GitHub commit.
- Create `.claude/skills/private-fields-with-accessors/` in your project and save the reviewed file as `.claude/skills/private-fields-with-accessors/SKILL.md`.
- Start Claude Code from that project's root, then select `/private-fields-with-accessors` in the slash menu.
Example task
Design a public trail name type backed by a boxed string. Let callers borrow its text, then validate the value returned by the accessor.
`TrailName` · `name: Box<str>` · `pub fn name(&self) -> &str` · `Pine Loop`What to check
`name()` returns `Pine Loop`. External callers use the read-only API, while the `name` field stays private.
Original SKILL.md on GitHub · Updated
Frequently asked question
How should the type support changing the name?
Provide a dedicated method that expresses the operation and preserves the type's invariants. Keep reads on the borrowed accessor.