rust-api-design
Skill4 starsChanged 3 months agoApache-2.0View on GitHub
Design idiomatic Rust APIs following best practices. Use when designing public crate APIs, creating libraries, writing documentation, choosing naming conventions, implementing builder patterns, or following the Rust API Guidelines.
We split this skill into the rules it gives an agent
3 rules. 0 are common, 3 are distinctive, and 0 are very specific to this project.
0
Common
Most of the 5 edited versions we read keep these.
3
Distinctive
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 179
Cargo feature organization: - Put new features behind flags
- Distinctive: line 180
Semantic versioning: - Follow semver for breaking changes
- Distinctive: line 182
Make invalid states unrepresentable: - Use types
“Common” is measured: kept by at least 6 in 10 of the 5 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Rust API Design
Guide to designing idiomatic Rust APIs based on the Rust API Guidelines.
When to Use This Skill
- Designing public crate APIs
- Creating library code
- Writing documentation for libraries
- Choosing naming conventions
- Implementing builder patterns
- Ensuring API consistency
Core References
- Rust API Guidelines - Official API guidelines
- Rust API Guidelines Checklist - Checklist
Naming Conventions
Functions and Methods
// Getters
struct Person { name: String }
impl Person {
fn name(&self) -> &str { &self.name }
}
// Boolean methods
impl Iterator {
fn next(&mut self) -> Option<Self::Item>;
fn len(&self) -> usize;
fn is_empty(&self) -> bool { self.len() == 0 }
}Types and Traits
// Types: PascalCase
struct ConfigFile;
enum HttpError;
type Result<T> = std::result::Result<T, Error>;
// Traits: adjectives (capable of X) or nouns (handler for X)
trait Readable;
trait Iterator;
trait Formatter;Modules
mod io; // Collection of I/O utilities
mod sync; // Synchronization primitives
pub mod error; // Re-exports error typesDocumentation
Doc Comments
/// Short description (one line).
///
/// Longer description with multiple lines.
///
/// # Panics
///
/// This function panics if x is 0.
///
/// # Examples
///
/// ```
/// assert_eq!(foo(2), 4);
/// ```
pub fn foo(x: i32) -> i32 {
x * 2
}Module Documentation
//! # My Crate
//!
//! A brief description of what this crate does.
//!
//! ## Usage
//!
//! Add to your Cargo.toml:
//!
//! ```toml
//! [dependencies]
//! my_crate = "1.0"
//! ```Error Handling
Use thiserror for Libraries
use thiserror::Error;
#[derive(Error, Debug)]
pub enum MyError {
#[error("configuration error: {0}")]
Config(#[from] std::io::Error),
#[error("parse error at position {position}: {message}")]
Parse { position: usize, message: String },
}Use anyhow for Applications
use anyhow::{Context, Result};
fn main() -> Result<()> {
let config = load_config()
.context("Failed to load configuration")?;
// ...
}Builder Pattern
pub struct Job {
name: String,
priority: i32,
retries: u32,
}
impl Job {
pub fn new(name: &str) -> Self {
Self {
name: name.to_string(),
priority: 0,
retries: 0,
}
}
pub fn priority(mut self, priority: i32) -> Self {
self.priority = priority;
self
}
pub fn retries(mut self, retries: u32) -> Self {
self.retries = retries;
self
}
}
// Usage
let job = Job::new("build")
.priority(10)
.retries(3);Reference Map
references/naming.md- Naming conventionsreferences/documentation.md- Writing docsreferences/error-handling.md- Error patternsreferences/ builders.md- Builder patternreferences/interoperability.md- C/FFI compatibility
Key Principles
- Cargo feature organization - Put new features behind flags
- Semantic versioning - Follow semver for breaking changes
- Minimal surface area - Expose only what's necessary
- Make invalid states unrepresentable - Use types
Key References
Other versions6 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 6
- rcore-os/tgoskits★ 76same name
- full-stack-skills/rust-skills★ 8same name
- jscott3201/yet-more-skills★ 4same name
- Lu1sDV/skillsmd★ 2same name
- adxptived/Rust-Skills★ 1same name
- takurot/rust-skills-comprehensive★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository80 other files it gives its agents.
- a11y-accessibility-designSkill
- agentic-ui-patternsSkill
- ai-native-ui-designSkill
- ai-ui-anti-patternsSkill
- ai-ui-heuristicsSkill
- calm-technology-uiSkill
- conversion-growth-designSkill
- cross-platform-designSkill
- dark-mode-designSkill
- data-visualizationSkill
- design-systemsSkill
- design-thinking-processSkill
- error-empty-statesSkill
- ethical-design-patternsSkill
- form-uxSkill
- information-architectureSkill
- interaction-design-patternsSkill
- internationalization-uiSkill
- mobile-touch-designSkill
- modal-classes-lifecycleSkill
- modal-container-imagesSkill
- modal-dicts-queuesSkill
- modal-endpointsSkill
- modal-fundamentalsSkill
- modal-gpu-computeSkill
- modal-networkingSkill
- modal-observabilitySkill
- modal-parallel-executionSkill
- modal-sandboxesSkill
- modal-scaling-performanceSkill
- modal-schedulingSkill
- modal-secretsSkill
- modal-serversSkill
- modal-storageSkill
- modal-web-servingSkill
- modal-workspace-adminSkill
- motion-design-principlesSkill
- notifications-permissionsSkill
- onboarding-uxSkill
- rust-async-programmingSkill
- rust-cargo-masterySkill
- rust-cli-applicationsSkill
- rust-clippy-lintsSkill
- rust-closures-iteratorsSkill
- rust-compiler-internalsSkill
- rust-concurrencySkill
- rust-design-patternsSkill
- rust-editionsSkill
- rust-embeddedSkill
- rust-error-handlingSkill
- rust-game-developmentSkill
- rust-lifetimes-borrowingSkill
- rust-macrosSkill
- rust-performanceSkill
- rust-rustdocSkill
- rust-rustup-toolchainSkill
- rust-smart-pointersSkill
- rust-testing-benchmarkingSkill
- rust-type-systemSkill
- rust-unsafe-ffiSkill
- The first 60 shown.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

