agentleFS
botirkhaltaevbotirkhaltaev/botir-skills/skills/rust-api-design/SKILL.md

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
  1. Distinctive:

    Cargo feature organization: - Put new features behind flags

    line 179
  2. Distinctive:

    Semantic versioning: - Follow semver for breaking changes

    line 180
  3. Distinctive:

    Make invalid states unrepresentable: - Use types

    line 182

“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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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

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 types

Documentation

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 conventions
  • references/documentation.md - Writing docs
  • references/error-handling.md - Error patterns
  • references/ builders.md - Builder pattern
  • references/interoperability.md - C/FFI compatibility

Key Principles

  1. Cargo feature organization - Put new features behind flags
  2. Semantic versioning - Follow semver for breaking changes
  3. Minimal surface area - Expose only what's necessary
  4. Make invalid states unrepresentable - Use types

Key References

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.