LLM plugin for pulling Rust crate documentation using cargo doc and other tools. This plugin allows you to directly feed Rust crate docs into your LLM queries using fragments.
For background on llm fragments see Simon Willison's blog.
Install this plugin in the same environment as LLM.
llm install llm-fragments-rustFor development installation:
git clone https://github.com/huitseeker/llm-fragments-rust.git
cd llm-fragments-rust
llm install -e .You can feed the docs of a Rust crate into LLM using the rust: fragment with the crate name, optionally followed by a version suffix.
# Using a specific version
llm -f rust:serde@1.0.188 "Explain how to deserialize a custom data type in Rust"
# Using latest version
llm -f rust:tokio "How do I spawn a new task?"
# Asking about multiple crates
llm -f rust:rand@0.8.5 -f rust:tokio "How do I generate random numbers asynchronously?"When you use the rust: fragment:
- The plugin creates a minimal Rust project in a temporary directory
- It adds the requested crate as a dependency with the specified version
- It generates documentation using
cargo doc - It extracts and processes the documentation into a readable format
- The extracted documentation is fed into the LLM context for your query
If the standard documentation methods fail, the plugin will attempt to fall back to simpler approaches:
- First extracting data from the HTML docs
- Using
cargo treeandcargo metadatato get dependency information - Finally, trying to pull basic information from crates.io API
- Rust and Cargo installed and available in PATH
- LLM 0.24 or higher
- Required standard Rust tools:
cargo(for building and managing dependencies)rustdoc(for documentation generation)
llm -f rust:serde_json "How do I parse JSON with unknown structure?"llm -f rust:tokio@1.0.0 -f rust:tokio@1.36.0 "What are the key differences between these versions?"llm -f rust:axum "Explain how to build a basic web server"If you encounter issues:
- Make sure Rust and Cargo are properly installed and in your PATH
- Check that you're using a recent version of the LLM CLI (0.24+)
- For development, try reinstalling with
llm install -e . - If a crate fails to load, try a simpler or more popular crate to verify the plugin works