▸ Agent Skills
3 min read

Zero-Hallucination Rustdoc and Docs.rs Guide

A practical workflow for AI agents to query docs.rs and local rustdoc outputs with zero hallucination.


The Hallucination Problem in Rust Libraries

Rust libraries evolve rapidly. Crate APIs rename structs, change method signatures, transition from returning T to Result<T, E>, or replace modules across minor versions. Relying on pretrained memory often produces deprecated or non-existent method calls.

To achieve reliable, error-free implementations, verify symbol names and signatures using the four verification tiers below.


Tier 1: Local Ground Truth (cargo doc)

When working inside a Rust repository, local documentation generated by cargo doc reflects the exact pinned crate versions from Cargo.lock.

Generate Local Docs

Run cargo doc without dependencies, or target specific crates:

# Build docs for egui and bevy_egui only (fast):
cargo doc -p egui -p bevy_egui --no-deps

The compiled HTML files reside in target/doc/.

Inspecting Local Docs

Search for items or methods using standard file inspection tools:

# List all items in the crate:
find target/doc/egui/ -maxdepth 2 -name "*.html"

# Search for a method on struct Ui:
grep -in "pub fn add" target/doc/egui/struct.Ui.html | head -n 20

Tier 2: Deterministic Docs.rs URL Navigation

Every crate on docs.rs uses a predictable, deterministic URL structure. You do not need a search engine or browser to locate items.

The Item Index (all.html)

Every rustdoc build includes an all.html file listing every public struct, enum, trait, function, and macro in the crate:

  • egui: https://docs.rs/egui/latest/egui/all.html
  • bevy_egui: https://docs.rs/bevy_egui/latest/bevy_egui/all.html
  • Version-pinned: https://docs.rs/egui/0.36.0/egui/all.html

Query this page via command line or HTTP fetch to check whether a symbol exists:

# Verify if a symbol exists and see its module path:
curl -sL "https://docs.rs/egui/latest/egui/all.html" | grep -i "CornerRadius"

Deterministic Item URLs

Direct links follow strict naming conventions:

  • Structs: https://docs.rs/<crate>/latest/<crate>/[module/]struct.<StructName>.html
    • Example: https://docs.rs/egui/latest/egui/struct.Ui.html
    • Example: https://docs.rs/bevy_egui/latest/bevy_egui/struct.EguiContexts.html
  • Enums: https://docs.rs/<crate>/latest/<crate>/[module/]enum.<EnumName>.html
    • Example: https://docs.rs/egui/latest/egui/enum.Id.html
  • Traits: https://docs.rs/<crate>/latest/<crate>/[module/]trait.<TraitName>.html
    • Example: https://docs.rs/egui/latest/egui/trait.Widget.html
  • Functions: https://docs.rs/<crate>/latest/<crate>/[module/]fn.<fn_name>.html
  • Schedules / SystemSets: https://docs.rs/bevy_egui/latest/bevy_egui/struct.EguiPrimaryContextPass.html

Tier 3: Rustdoc Search Index

Rustdoc generates a client-side search index named search-index.js alongside the HTML files. It contains JSON arrays of every item, method signature, and docstring.

# Query items in search-index.js directly:
curl -sL "https://docs.rs/egui/latest/search-index.js" | grep -o -E '"[a-zA-Z0-9_]+"' | grep -i "slider" | head -n 15

Tier 4: The Compiler Diagnostic Feedback Loop

The rustc compiler is one of the most informative developer tools available. When unsure about a method name or signature:

  1. Draft the minimal code block using idiomatic types.
  2. Run cargo check 2>&1 | head -n 35.
  3. Read the compiler diagnostics:
    • If a method was renamed, rustc suggests: help: there is a method with a similar name: '...'.
    • If an import is missing, rustc suggests: help: consider importing this struct: 'use egui::...'.
    • If types mismatch, rustc states the exact expected vs found types.
  4. Apply the compiler suggestion and re-run cargo check.

Last updated Oct 08, 2026