13-usage-examples

Chapter 13 — Usage & Examples

This chapter provides practical examples of how to run ratcrate-core, how to inspect its output, and how to troubleshoot common workflows.


1. Basic Usage

Clone the crates.io sparse index

git clone https://github.com/rust-lang/crates.io-index.git sparse-index

1. Run ratcrate-core

cargo run -- -s sparse-index

This will:

  • Scan the sparse index
  • Identify crates depending on ratatui
  • Fetch crates.io metadata
  • Save caches to cache/
  • Produce: output/ratcrate.json

2. Using a Sample Index for Faster Testing

Useful when building or debugging:

sample-index/
  a/
    a/
      a

Run:

$> cargo run -- -s sample-index

3. Viewing the Output JSON

Pretty-print with `jq

$> jq '.' output/ratcrate.json

4. View downloads for the top 10 crates

$> jq '.crates | sort_by(.downloads) | reverse | .[0:10]'

5. Find crates without a repository URL

$> jq '.crates[] | select(.repository == null) | .name'

4. Quick Code Examples

Load ratcrate.json in Rust

use std::fs;

fn main() {
    let data = fs::read_to_string("output/ratcrate.json").unwrap();
    let parsed: ratcrate_core::CratesData = serde_json::from_str(&data).unwrap();
    println!("{:#?}", parsed.metadata.statistics);
}

Load ratcrate.json in Python

import json

with open("output/ratcrate.json") as f:
    data = json.load(f)

print("Total crates:", len(data["crates"]))

5. Tips

Always clone the sparse index with full depth (no partial clones).

Use CRATES_IO_TOKEN for fewer rate limits.

Run daily or weekly for incremental updates.

Placeholder: Screenshots

Screenshot: running cargo run – -s sparse-index

Screenshot: ratcrate.json preview

Screenshot: jq queries