DO

documenting-rust-code

Guidelines for writing high-quality Rust documentation following industry standards.

Install

mkdir -p .claude/skills/documenting-rust-code && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/3502" && unzip -o skill.zip -d .claude/skills/documenting-rust-code && rm skill.zip

Installs to .claude/skills/documenting-rust-code

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

Rust documentation practices for HASH codebase. Use when writing doc comments, documenting functions/types/traits/modules, creating error sections, using intra-doc links, or following rustdoc conventions.
204 chars✓ has a “when” trigger
Beginner

Key capabilities

  • Write doc comments with summaries
  • Create intra-doc links for types
  • Document error conditions
  • Include practical API examples
  • Format module-level documentation

How it works

The skill enforces rustdoc conventions by requiring summaries, error sections, and intra-doc links for all public APIs.

Inputs & outputs

You give it
Rust source code
You get back
Compliant documentation comments

When to use documenting-rust-code

  • Write module doc comments
  • Add error sections to documentation
  • Link to standard library types
  • Document a public trait

About this skill

Rust Documentation Practices

Comprehensive guidance on documenting Rust code in the HASH repository following rustdoc conventions.

Core Principles

Follow high-quality standards like time, jiff, and serde:

DO:

  • Begin every doc comment with single-line summary
  • Use intra-doc links for all type references
  • Document all error conditions with # Errors
  • Include practical examples for public APIs
  • Link standard library types: [Vec], [HashMap], etc.
  • Use inline parameter descriptions for simple functions (0-2 params)
  • Describe return values in main text, not separate sections

DON'T:

  • Document standard trait implementations (Debug, Display, From)
  • Add separate # Returns sections (inline instead)
  • Mention variable types already in signatures
  • Use comments on same line as code
  • Skip error documentation for fallible functions

Quick Reference

Basic Doc Comment

/// Retrieves an entity by its UUID.
///
/// Loads the entity from the store and verifies access permissions.
/// Returns the [`Entity`] if found and accessible.
///
/// # Errors
///
/// - [`NotFound`] if the entity doesn't exist
/// - [`AuthorizationError`] if access is denied
///
/// [`NotFound`]: EntityError::NotFound
/// [`AuthorizationError`]: EntityError::Authorization
pub fn get_entity(&self, id: EntityId) -> Result<Entity, Report<EntityError>> {

Intra-Doc Links

/// Updates the [`User`] using [`UserUpdateStrategy`].
///
/// See [`validation::user`] for validation rules.
///
/// [`validation::user`]: crate::validation::user

Documentation Patterns

Simple Functions (0-2 params)

Describe parameters inline:

/// Processes the `input` elements and returns filtered results.
///
/// Takes a collection of `input` elements, applies the `filter_fn`,
/// and returns a [`Vec`] containing only matching elements.

Complex Functions (3+ params)

Use explicit # Arguments section:

/// Merges multiple data sources with transformation rules.
///
/// # Arguments
///
/// * `sources` - Collection of data sources to merge
/// * `rules` - Transformation rules to apply
/// * `options` - Configuration controlling merge behavior
/// * `callback` - Optional function for each merged item

Error Documentation

/// # Errors
///
/// - [`WebAlreadyExists`] if web ID is taken
/// - [`AuthorizationError`] if permission denied
///
/// [`WebAlreadyExists`]: WebError::WebAlreadyExists
/// [`AuthorizationError`]: WebError::Authorization

Module Documentation

//! Entity management functionality.
//!
//! Main types:
//! - [`Entity`] - Core entity type
//! - [`EntityStore`] - Storage trait
//!
//! # Examples
//!
//! ```
//! use hash_graph::entity::Entity;
//! ```

Examples with Error Handling

/// # Examples
///
/// ```rust
/// let entities = get_entities_by_type(type_id)?;
/// assert_eq!(entities.len(), 2);
/// # Ok::<(), Box<dyn core::error::Error>>(())
/// ```

Verification

cargo doc --no-deps --all-features

References

When not to use it

  • Documenting standard trait implementations

Prerequisites

cargo doc

Limitations

  • Requires manual maintenance of doc comments
  • Limited to Rust documentation conventions

How it compares

It mandates a high-quality standard similar to major Rust crates, ensuring consistency across the entire codebase.

Compared to similar skills

documenting-rust-code side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
documenting-rust-code (this skill)12moReviewBeginner
review-rust-docs15moNo flagsBeginner
deepwiki-rs259moReviewIntermediate
code-review06moNo flagsIntermediate

Try saying

Example prompts that trigger this skill in your AI assistant.

More by hashintel

View all by hashintel

handling-rust-errors

hashintel

HASH error handling patterns using error-stack crate. Use when working with Result types, Report types, defining custom errors, propagating errors with change_context, adding context with attach, implementing Error trait, or documenting error conditions in Rust code.

46

exploring-rust-crates

hashintel

Generate Rust documentation to understand crate APIs, structure, and usage. Use when exploring Rust code, understanding crate organization, finding functions/types/traits, or needing context about a Rust package in the HASH workspace.

33

writing-hashql-jexpr

hashintel

HashQL J-Expr syntax for writing queries. Use when writing J-Expr code, using #literal/#struct/#list constructs, understanding function call syntax, or working with HashQL query files (.jsonc).

25

managing-cargo-dependencies

hashintel

Cargo.toml dependency management patterns for HASH workspace. Use when adding, updating, or removing dependencies, organizing Cargo.toml sections, configuring version pinning and default features, or managing public dependencies.

13

managing-git-workflow

hashintel

Git workflow for HASH including branch naming, PR creation, and PR reviews. Use when creating branches, making commits, opening pull requests, or reviewing PRs.

12

testing-hashql

hashintel

HashQL testing strategies including compiletest (UI tests), unit tests, and snapshot tests. Use when writing tests for HashQL code, using //~ annotations, running --bless, debugging test failures, or choosing the right testing approach.

11

Search skills

Search the agent skills registry