Expand description
§rustdoc-text
A lightweight library to view Rust documentation as plain text (Markdown).
This crate provides both a library and a binary for accessing Rust documentation in plain text format.
§rustdoc-text
A lightweight library and CLI tool to view Rust documentation as plain text (Markdown) in the terminal.
Similar to tools like pydoc
and godoc
, but for Rust documentation.
§Features
- View documentation for any Rust crate directly in your terminal as Markdown
- Access documentation locally (builds as needed) or from docs.rs
- Lightweight and fast with minimal dependencies
- Simple command-line interface
- Can be used as a library in your Rust code
§Installation
cargo install rustdoc-text
§Command-line Usage
# View documentation for a crate
rustdoc-text serde
# View documentation for a specific item in a crate
rustdoc-text serde Deserializer
# View documentation from docs.rs (instead of building locally)
rustdoc-text --online tokio
# Get help
rustdoc-text --help
§Library Usage
use rustdoc_text::Config;
use anyhow::Result;
fn main() -> Result<()> {
// Simple usage
let docs = Config::new("serde")
.with_online(true)
.execute()?;
println!("{}", docs);
// Or use the functions directly
let tokio_docs = rustdoc_text::fetch_online_docs("tokio", Some("Runtime"))?;
println!("{}", tokio_docs);
Ok(())
}
§How it works
This tool:
- Fetches Rust documentation (either by building locally or from docs.rs)
- Extracts the main content section from the HTML
- Converts the HTML to Markdown using the htmd library
- Outputs clean, readable Markdown to stdout
§Why Markdown?
Markdown is a lightweight markup language that’s very readable as plain text, making it ideal for terminal output. It preserves the structure of the documentation while being much more readable than raw HTML.
§Dependencies
htmd
: For HTML to Markdown conversionclap
: For command-line argument parsingreqwest
: For fetching online documentationanyhow
: For error handlingscraper
: For HTML parsing
§License
This project is licensed under the MIT License - see the LICENSE file for details.
Structs§
- Config
- Configuration options for fetching Rust documentation.
Functions§
- clean_
markdown - Clean up the markdown output to make it more readable in terminal.
- fetch_
local_ docs - Builds and fetches Rust documentation locally and converts it to Markdown.
- fetch_
online_ docs - Fetches Rust documentation from docs.rs and converts it to Markdown.
- process_
html_ content - Process HTML content to extract and convert relevant documentation parts to Markdown.