idiomatic-rust
FreeNo executable scriptsNot checkedIdiomatic Rust patterns for pikru C port. Use when writing or reviewing Rust code ported from C. Don't write C in Rust - the goal is correct behavior, not…
About this skill
Idiomatic Rust: Don't port C patterns
This is a Rust port of C code, but do not write C in Rust. The goal is correct behavior, not line-by-line translation.
Put logic where the data lives
If a struct has all the information needed to compute something, make it a method:
// BAD: C-style function with boolean flag soup
fn text_width(text: &str, charwid: f64, is_mono: bool, font_scale: f64, is_bold: bool) -> f64
// GOOD: The type already knows its properties
impl PositionedText {
fn width_inches(&self, charwid: f64) -> f64 {
// self.mono, self.bold, self.big are all right here
}
}
Rationale: Boolean flags are:
- Easy to pass in wrong order (
width(s, w, true, 1.0, false)- which bool is which?) - Require the caller to extract properties just to pass them back in
- Duplicate knowledge that the type already has
Use newtypes for domain concepts
// BAD: Bare f64 everywhere, easy to mix up inches and pixels
fn convert(value: f64, scale: f64) -> f64
// GOOD: The type system catches mistakes
struct Inches(f64);
struct Pixels(f64);
fn convert(value: Inches, scale: &Scaler) -> Pixels
Prefer methods over standalone functions
When you find yourself writing foo_bar(bar, ...), consider bar.foo(...) instead. This:
- Groups related functionality
- Enables IDE autocomplete on the type
- Makes the relationship between data and operations explicit
Enums over boolean flags
// BAD: What does `true` mean here?
render_text(text, true, false)
// GOOD: Self-documenting
enum TextAnchor { Start, Middle, End }
render_text(text, TextAnchor::Start)
The C code is a spec, not a template
When porting C:
- Understand what the C code does (behavior)
- Understand why it does it (intent)
- Implement that behavior idiomatically in Rust
The // cref: comments link to C for reference, but the Rust should stand on its own.
Install idiomatic-rust in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
FAQ
What does the idiomatic-rust skill do?
Idiomatic Rust patterns for pikru C port. Use when writing or reviewing Rust code ported from C. Don't write C in Rust - the goal is correct behavior, not line-by-line translation.
How do I install the idiomatic-rust skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the idiomatic-rust skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
by Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
by Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
by Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
by Anthropic