Expand description
CRATOR
This 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.
This library implements a custom, dependency-free blocking runner
to manage networking tasks. It intentionally avoids heavy runtimes like tokio,
relying instead on the Standard Library
and native-tls for secure HTTPS connections.
§Key Features
- Zero-Dependency JSON Extraction: Custom parsing logic without
serde_json. - Custom block_on Implementation: Built-in “Spin-then-Yield” strategy for running futures to completion—no
tokioorasync-stdrequired. - 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).
§Features
- Zero-Dependency JSON Extraction: Custom parsing logic without
serde_json. - Custom block_on Runner: Built-in “Spin-then-Yield” strategy—no
tokioorasync-stdrequired. - 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 cratorOr 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 fromnative-tlsfor zero-config secure connections.Instant: Re-exported fromstd::timefor 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.
Structs§
- Crate
Info - Represents the essential metadata of a crate retrieved from crates.io.
- Instant
- A measurement of a monotonically nondecreasing clock.
Opaque and useful only with
Duration. - Json
- A lightweight, zero-dependency JSON extractor designed for maximum performance.
- TlsConnector
- A builder for client-side TLS connections.
Functions§
- block_
on - A high-performance, single-threaded runner for driving Futures to completion.
- crate_
data - Fetches crate data from the crates.io API given a crate name.
- format_
number - Formats large numbers into human-readable strings.