Crate rustdoc_text

Source
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:

  1. Fetches Rust documentation (either by building locally or from docs.rs)
  2. Extracts the main content section from the HTML
  3. Converts the HTML to Markdown using the htmd library
  4. 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 conversion
  • clap: For command-line argument parsing
  • reqwest: For fetching online documentation
  • anyhow: For error handling
  • scraper: 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.