Rust Language SupportΒΆ

Automatic documentation extraction for Rust packages

Rust Language SupportΒΆ

Introligo provides automatic documentation extraction for Rust crates, seamlessly integrating Rust API documentation into your Sphinx site.

OverviewΒΆ

Similar to Go and Java support, Rust documentation is extracted directly from your Rust source code using cargo doc and converted to reStructuredText format. This provides a clean, native Sphinx experience without requiring external tools beyond Cargo itself.

FeaturesΒΆ

βœ… Automatic Extraction - Runs cargo doc to build documentation and extracts content from source βœ… RST Conversion - Converts Rust documentation comments to properly formatted reStructuredText βœ… Seamless Integration - Extracted docs appear directly in your Sphinx site βœ… Graceful Fallback - Works even without Cargo installed (provides docs.rs links) βœ… Manual Override - Option to provide manual documentation when needed

Basic UsageΒΆ

Minimal ConfigurationΒΆ

modules:
  my_crate:
    title: "My Rust Crate"
    language: rust
    rustdoc_crate: "my_crate"
    rustdoc_path: "."

Configuration FieldsΒΆ

Field

Description

Required

language: rust

Specifies Rust language

Yes

rustdoc_crate

Rust crate name

Recommended

rustdoc_path

Path to crate directory (relative to config)

Recommended

rustdoc_manual_content

Manual documentation (fallback)

Optional

How It WorksΒΆ

Automatic Extraction ProcessΒΆ

  1. Detection: Introligo detects language: rust in your configuration

  2. Execution: Runs cargo doc –no-deps to build documentation

  3. Parsing: Extracts documentation comments from source files (lib.rs, main.rs)

  4. Conversion: Parses doc comments and converts to RST format

  5. Integration: Injects the formatted documentation into your Sphinx build

Example FlowΒΆ

Your YAML Config
    ↓
Introligo Generator
    ↓
cargo doc --no-deps
    ↓
Parse Rust source (lib.rs)
    ↓
Extract doc comments (//!, ///)
    ↓
Generate Sphinx RST files
    ↓
Beautiful Documentation!

Complete ExampleΒΆ

sphinx:
  project: "My Rust Project"
  html_theme: "furo"

modules:
  api_reference:
    title: "API Reference"
    description: "Complete API documentation"

  calculator:
    parent: "api_reference"
    title: "Calculator Crate"
    language: rust
    description: "Arithmetic operations crate"

    # Crate configuration
    rustdoc_crate: "calculator"
    rustdoc_path: "./calculator"

    # Your narrative documentation
    overview: |
      The Calculator crate provides simple arithmetic operations
      for numeric values with proper error handling.

    features:
      - "Addition and subtraction operations"
      - "Multiplication and division with zero-check"
      - "Error handling for edge cases"
      - "Generic numeric type support"

    usage_examples:
      - title: "Basic Usage"
        language: "rust"
        code: |
          use calculator::Calculator;

          fn main() {
              let calc = Calculator::new();
              let result = calc.add(5, 3);
              println!("{}", result);  // Output: 8
          }

      - title: "Error Handling"
        language: "rust"
        code: |
          use calculator::Calculator;

          fn main() {
              let calc = Calculator::new();
              match calc.divide(10, 2) {
                  Ok(result) => println!("Result: {}", result),
                  Err(e) => eprintln!("Error: {}", e),
              }
          }

Generated DocumentationΒΆ

The above configuration generates documentation with:

Crate-Level DocumentationΒΆ

Extracted from module-level comments in your Rust code (//! comments)

Function DocumentationΒΆ

pub fn add(a: i32, b: i32) -> i32

Adds two integers and returns the sum.

Parameters: - a - The first integer - b - The second integer

Returns: The sum of a and b.

Type DocumentationΒΆ

All public items (structs, enums, traits, functions) with their documentation

Manual Documentation FallbackΒΆ

When Cargo is not installed or the crate is not accessible, you can provide manual documentation:

modules:
  my_crate:
    language: rust
    rustdoc_crate: "my_crate"

    # Manual documentation (used as fallback)
    rustdoc_manual_content: |
      Crate provides awesome functionality.

      Functions
      ~~~~~~~~~

      .. code-block:: rust

         pub fn do_something(input: &str) -> Result<String, Error>

      Performs an operation on the input string.

      **Parameters:**
      - ``input`` - The input string to process

      **Returns:** A Result with the processed string or an error.

RequirementsΒΆ

For Automatic ExtractionΒΆ

  • Rust and Cargo installed

  • Valid Cargo.toml in crate directory

  • Source code in src/ directory

For Manual Documentation OnlyΒΆ

  • No special requirements

  • Works with just Sphinx and Introligo

Best PracticesΒΆ

1. Write Good Rustdoc CommentsΒΆ

//! # Calculator Crate
//!
//! This crate provides basic arithmetic operations
//! with proper error handling.

/// Adds two integers and returns the sum.
///
/// # Examples
///
/// ```
/// let result = add(5, 3);
/// assert_eq!(result, 8);
/// ```
pub fn add(a: i32, b: i32) -> i32 {
    a + b
}

2. Use Descriptive Crate NamesΒΆ

rustdoc_crate: "my_awesome_calculator"
rustdoc_path: "./crates/calculator"

3. Organize with ParentsΒΆ

modules:
  api:
    title: "API Reference"

  core_crate:
    parent: "api"
    language: rust
    rustdoc_crate: "myproject_core"
    rustdoc_path: "./crates/core"

  utils_crate:
    parent: "api"
    language: rust
    rustdoc_crate: "myproject_utils"
    rustdoc_path: "./crates/utils"

4. Combine with Narrative DocsΒΆ

modules:
  my_crate:
    language: rust
    rustdoc_crate: "my_crate"
    rustdoc_path: "."

    # Add context with narrative sections
    overview: "Why this crate exists..."
    installation: "cargo add my_crate"
    usage_examples: [...]
    best_practices: [...]

TroubleshootingΒΆ

Cargo Not FoundΒΆ

Problem: WARNING: Cargo is not installed - skipping documentation extraction

Solution: - Install Rust and Cargo from https://rustup.rs/ - Ensure cargo is in your PATH - Or provide rustdoc_manual_content as fallback

Crate Not FoundΒΆ

Problem: Cargo doc fails to find the crate

Solution: - Check that rustdoc_path points to correct directory - Verify Cargo.toml exists in the path - Ensure the crate builds with cargo build

Empty DocumentationΒΆ

Problem: No documentation appears even though extraction succeeds

Solution: - Add rustdoc comments to your Rust code - Use proper comment format: /// for items, //! for modules - Check that items are public (marked with pub)

Comparison with Other LanguagesΒΆ

Feature

Python

Go

Java

Rust

Extraction Tool

autodoc

go doc

Source parser

cargo doc

Automatic

βœ… Yes

βœ… Yes

βœ… Yes

βœ… Yes

External Tool

No

No*

No

Yes

Format

Docstrings

Comments

Comments

Doc comments

Manual Fallback

No

βœ… Yes

βœ… Yes

βœ… Yes

*Requires Go to be installed

See AlsoΒΆ

SummaryΒΆ

Introligo’s Rust support provides:

βœ… Automatic extraction using cargo doc βœ… Clean RST conversion for Sphinx βœ… Seamless integration with your docs βœ… Graceful fallback when Cargo unavailable βœ… Manual override option for flexibility

Start documenting your Rust crates today!