documenting-rust-code

Document Rust code with rustdoc-compliant doc comments.

1.6k|123|Updated Jul 15, 2019
One-click install
npx skills add https://github.com/hashintel/hash --skill documenting-rust-code
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: documenting-rust-code
Source: https://github.com/hashintel/hash/tree/main/.claude/skills/documenting-rust-code
Command: npx skills add https://github.com/hashintel/hash --skill documenting-rust-code

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides comprehensive guidance for writing high-quality Rust documentation in the HASH repository, ensuring consistency, navigability, and adherence to rustdoc conventions. It streamlines code understanding, accelerates developer onboarding, and reduces the effort required to maintain accurate API documentation.

Core Features & Use Cases

  • Function & Type Documentation: Learn to structure doc comments for functions, methods, structs, enums, and traits, including single-line summaries and detailed descriptions.
  • Error & Panic Sections: Guides you to document all fallible functions with # Errors sections, linking error variants, and to use # Panics for functions that might panic, ensuring complete API contracts.
  • Intra-Doc Links: Master the [...] syntax for internal and standard library type references, making your documentation highly navigable and interconnected.
  • Compilable Code Examples: Learn to include compilable # Examples sections for public APIs, demonstrating practical usage and error handling, making your code easier to adopt.
  • Use Case: When writing a new public function, this skill guides you to start with a concise summary, describe parameters inline, detail return values, add an # Errors section with intra-doc links for all potential error variants, and include a practical code example demonstrating its usage.

Quick Start

Use the documenting-rust-code skill to write documentation for the 'create_user' function, including its parameters, return value, and potential errors.

Frequently Asked Questions about documenting-rust-code

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write rustdoc comments for Rust functions?

Rustdoc comments start with a single-line summary, then add inline parameter descriptions for simple functions or explicit `# Arguments` sections for complex ones. Include `# Errors` for fallible functions, `# Panics` if applicable, intra-doc links using `[`...`]` syntax, and compilable `# Examples` blocks demonstrating usage.

What should I include in Rust API documentation?

API documentation requires a concise summary, parameter and return value descriptions, `# Errors` sections with intra-doc links to error variants, `# Panics` for panic conditions, `# Performance` notes when relevant, and compilable code examples showing practical usage and error handling patterns.

How do intra-doc links work in Rust documentation?

Intra-doc links use `[`type_name`]` syntax to reference functions, types, traits, and modules within your crate or the standard library. They create clickable connections in generated HTML docs, improving navigability and making documentation more interconnected and discoverable.

Can I include executable examples in Rust doc comments?

Yes, `# Examples` sections in doc comments contain compilable Rust code that demonstrates function usage. These examples run during `cargo test`, catching documentation drift and ensuring examples remain valid as code evolves.

When do I need to document errors in Rust functions?

All fallible functions—those returning `Result` types—require `# Errors` sections listing potential error variants with intra-doc links and descriptions. This documents the complete API contract and helps users understand failure modes and error handling.

Does rustdoc enforce documentation standards for public APIs?

Rustdoc is Rust's built-in documentation generator that enforces rustdoc-compliant conventions through linting and compilation. It validates doc comment structure, intra-doc links, and example code, ensuring consistency and high-quality API documentation across public types, functions, traits, and modules.