crator 0.7.1

The CRATOR library offers core functions to retrieve crate metadata from crates.io via raw TCP/TLS connections, process the JSON response, and present the data in a user-friendly format.
Documentation

Features

  • Zero-Dependency JSON Extraction: Custom parsing logic without serde_json.
  • Custom block_on Runner: Built-in "Spin-then-Yield" strategy—no tokio or async-std required.
  • Minimal Footprint: Only one external dependency (native-tls) for secure HTTPS.
  • Deep Path Support: Robust dot-notation extraction (e.g., metadata.stats.0.count).
  • Human-Readable Formatting: Compacts large numbers (e.g., 56000 -> 56k)

About

crator is a high-performance utility designed for CLI tools where binary size and execution speed are critical. While most libraries rely on heavy async frameworks and full JSON serializers, crator achieves its minimal footprint by utilizing raw TCP/TLS streams and manual string-slice processing via a custom block_on runner.

By bypassing the overhead of traditional frameworks, it offers a direct, ultra-fast path to retrieve crate metadata from crates.io, process the response with a zero-copy extractor, and present the data in a clean, user-friendly format.

Installation

To include crator in your Rust project, run:

cargo add crator

Or add crator to your Cargo.toml. Since crator re-exports its TLS connector, no other dependencies are required.

[dependencies]

crator = "MAJOR.MINOR.PATCH"

Key Components

  • CrateInfo: Struct holding metadata like versions, download counts, and license info.
  • crate_data: Async function that performs secure HTTPS requests to the crates.io API.
  • Json: A zero-dependency utility for ultra-fast value extraction.
  • block_on: A custom, lightweight "Spin-then-Yield" runner for driving futures to completion.
  • format_number: Function to convert large numbers into compact strings (e.g., 56k).
  • TlsConnector: Re-exported from native-tls for zero-config secure connections.
  • Instant: Re-exported from std::time for easy high-precision benchmarking.

Examples

use crator::{crate_data, block_on};

fn main() {
    let crate_name = "mathlab";
    
    // Use the built-in lightweight runner to drive the fetch to completion
    let info = block_on(async move {
        crate_data(crate_name).await
    }).expect("Failed to fetch crate data");

    println!("Latest: v{}, Downloads: {}", info.latest, info.downloads);
}
use crator::*;

fn main() {
    let crate_name = "fluxor";
    let start = Instant::now();

    // Work happens here...
    let info = block_on(crate_data(crate_name)).expect("Failed to get crate info");

    // ...then print the timing!
    println!("🦀 Fetching [{}] done in {:?}", crate_name, start.elapsed());

    println!("Latest:    v{}", info.latest);
    println!("Versions:  {}", info.versions);
    println!("Downloads: {}", info.downloads);
} 
use crator::*;

fn main() {
    let crate_name = "mathlab";
    let start = Instant::now();

    // 1. Run the custom block_on runner (This is the heavy lifting)
    let result = block_on(crate_data(crate_name));

    // 2. Measure and print the timing AFTER it's done
    println!("🦀 Fetching [{}] done in {:?}", crate_name, start.elapsed());

    // 3. Match the result to display the metadata
    match result {
        Ok(info) => {
            println!("Latest:             v{}", info.latest);
            println!("Downloads:          {}", info.downloads);
            println!("Total Downloads:    {}", info.total_downloads);
            println!("Versions:           {}", info.versions);
            println!("Created At:         {}", info.created_at);
            println!("Updated At:         {}", info.updated_at);
            println!("License:            {}", info.license);
        }
        Err(e) => eprintln!("❌ Error: {}", e),
    }
}

License

This project is licensed under the MIT License or Apache 2.0 License.nnector, no other dependencies are required.