Skip to content

Instantly share code, notes, and snippets.

@phase
Last active October 27, 2025 21:19
Show Gist options
  • Save phase/063cf1d88dc911f91c6b17e7d1fa15dd to your computer and use it in GitHub Desktop.
Save phase/063cf1d88dc911f91c6b17e7d1fa15dd to your computer and use it in GitHub Desktop.
description globs alwaysApply
Check Bevy source code locally for accurate API information
true

When working with Bevy, always check the LOCAL source code and documentation to ensure version accuracy.

Quick Access to Bevy Resources

Local Documentation (Preferred)

  • HTML Docs: target/doc/bevy/index.html
  • Generate: cargo doc --package bevy --open
  • All deps: cargo doc --open

Local Source Code (Most Accurate)

The exact Bevy version used in this project is available locally:

  • Main crate: ~/.cargo/registry/src/index.crates.io-*/bevy-0.16.1/
  • Individual crates: Each Bevy module is a separate crate:
    • bevy_ecs-0.16.1/ - Entity Component System
    • bevy_app-0.16.1/ - Application framework
    • bevy_render-0.16.1/ - Rendering pipeline
    • bevy_sprite-0.16.1/ - 2D sprites
    • bevy_transform-0.16.1/ - Transform components
    • And many more in ~/.cargo/registry/src/index.crates.io-*/bevy_*

Finding Specific APIs

# Search across ALL Bevy crates for a struct/trait/function
rg "struct ComponentId" ~/.cargo/registry/src/index.crates.io-*/bevy*0.16.1/

# Search in specific Bevy crate
rg "System" ~/.cargo/registry/src/index.crates.io-*/bevy_ecs-0.16.1/

# Check current Bevy version
grep "^name = \"bevy\"" Cargo.lock -A 1

# Open specific module docs
cargo doc --package bevy_ecs --open

Why Local Over GitHub

  • Version Match: Local source matches EXACTLY what your project uses
  • No Network: Faster access, works offline
  • Consistency: Avoids API breaking changes between versions
  • Complete: Includes all dependencies with correct versions

Bevy moves fast and breaks APIs between versions. Always prefer local source over web resources to avoid version mismatch errors.

description globs alwaysApply
Access local Rust crate documentation and source code for API reference
true

When working with Rust crates (including Bevy and any other dependencies), prioritize using local documentation and source code over web resources for better accuracy and version consistency.

Local Documentation Access

  1. Generated Documentation: Check target/doc/ for HTML documentation

    • If docs don't exist or are outdated, run: cargo doc
    • For specific crate docs: target/doc/<crate_name>/index.html
    • Example for Bevy: target/doc/bevy/index.html
  2. Opening Documentation:

    • Use cargo doc --open to generate and open in browser
    • For specific crate: cargo doc --package <crate_name> --open

Local Source Code Access

All downloaded crate source code is stored in the Cargo registry:

  1. Primary location: ~/.cargo/registry/src/

    • Format: ~/.cargo/registry/src/<registry>/<crate>-<version>/
    • Example: ~/.cargo/registry/src/index.crates.io-*/bevy-0.16.1/
  2. Finding specific crate source:

    • Check Cargo.lock for exact versions
    • Navigate to: ~/.cargo/registry/src/index.crates.io-*/<crate>-<version>/src/
  3. Git dependencies: Located in ~/.cargo/git/checkouts/

Workflow for API Investigation

When you need to understand a Rust API or see implementation details:

  1. First: Check if documentation exists in target/doc/
  2. If missing/outdated: Run cargo doc to generate fresh docs
  3. For source code: Navigate to ~/.cargo/registry/src/ for the exact version
  4. Use grep/ripgrep: Search within the local source for specific patterns
  5. Check examples: Look in the crate's examples/ directory in the source

Version Consistency

  • Always check Cargo.lock for the exact version being used
  • The local source in ~/.cargo/registry/src/ matches your project's dependencies exactly.
  • This ensures API compatibility and avoids version mismatch issues.

Example Commands

# Check the README.md of a specific crate
cat ~/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/bevy_pbr-0.16.1/README.md

# Generate and open documentation
cargo doc --open

# Generate docs for specific crate
cargo doc --package bevy --open

# Find Bevy source
ls ~/.cargo/registry/src/index.crates.io-*/bevy-0.16.1/

# Search for a specific API in local source
rg "struct ComponentId" ~/.cargo/registry/src/index.crates.io-*/bevy-0.16.1/

# Check exact version in use
grep "bevy" Cargo.lock | head -5

This approach ensures you're always looking at the exact version your project uses, avoiding API mismatches common with fast-moving libraries like Bevy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment