What is Rust Crator?
-
A lightweight, high-performance, and synchronous
HTTP/HTTPSclient forRust. -
A lightweight, zero-dependency
JSON extractordesigned for maximum performance and efficiency. -
High-performance functions to
fetchandinteractwith structured Crates.io APImetadata. -
Panic-free
utilitiesfor safely loading and managingenvironment variables.
1. crator::Http;
2. crator::Json;
3. crator::{CrateInfo, crate_data};
4. crator::{get_env, get_env_or};
Installation
To include crator in your Rust project, run:
cargo add crator
Or add crator to your Cargo.toml:
[]
= "MAJOR.MINOR.PATCH" # replace with the actual version
Http
A lightweight, high-performance, and synchronous HTTP/HTTPS client for Rust.
Overview
Crator::Http provides a simple yet powerful API for executing HTTP requests with minimal dependencies. It features connection pooling, automatic retries, native TLS support, and full method coverage, making it ideal for high-performance network applications.
Key Features
- Connection Pooling: Reuses
TCP/TLSstreams via a global agent for reduced latency. - Automatic Retries: Handles transient network failures automatically.
- Security: Uses system-native
TLSbackends (SChannel, OpenSSL, Secure Transport). - Full Method Support: Supports all standard
HTTPverbs (GET, POST, PUT, DELETE, etc) and WebDAV extensions (MOVE, LOCK, etc.).
Usage Examples
GET Request
use Http;
POST Request with JSON Body
use Http;
Handling Cookies
use Http;
HTTP Request Example: Fetching Crates.io Metadata
use Http;
Features
- Request Methods:
GET,POST,PUT,DELETE,PATCH,HEAD,OPTIONS,CONNECT,TRACE,COPY,MOVE,MKCOL,PROPFIND,LOCK,UNLOCK. - Custom Headers & Cookies: Easily add headers and cookies.
- Timeouts & Redirects: Set request timeouts; follow redirects automatically up to 5 times.
- Persistent Connections: Connection reuse via global agent.
Internal Architecture
- Uses a global
Agentfor connection pooling. - Supports both
HTTPandHTTPSprotocols. - Handles transfer encodings including
chunkedtransfer. - Retries on common transient network
errors.
Json
A lightweight, zero-dependency JSON extractor designed for maximum performance and efficiency.
Overview
Crator::Json provides a minimal and fast way to parse, navigate, and extract data from JSON strings in Rust. It features a simple enum-based structure, recursive data traversal, and no external dependencies, making it ideal for performance-critical applications.
Key Features
- Zero dependencies: No external crates required.
- Fast parsing: Custom recursive parser for maximum speed.
- Flexible navigation: Recursive search for keys within JSON structures.
- Type-safe accessors: Retrieve data as strings or numbers.
- Readable output: Pretty-print JSON with indentation.
- Indexing support: Access objects and arrays using
[]syntax.
Usage Examples
Parsing JSON
use Json;
Pretty Printing JSON
use Json;
let json_str = r#"{"name": "Rust", "features": ["performance", "safety"], "version": 0.8}"#;
let parsed = from_str;
println!;
Checking for Null Values
use Json;
let json_str = r#"{"name": "Rust", "features": ["performance", "safety"], "version": 0.8}"#;
let parsed = from_str;
if parsed.is_null
Features
- Recursive search:
find()method searches for keys at any depth. - Type conversion:
as_str(),as_f64()for safe type retrieval. - Flexible navigation: Index objects and arrays via [].
- Pretty print: Human-readable
JSON output. - No dependencies: Zero external crates.
Internal Architecture
- Uses a custom recursive parser to convert
JSONstrings into aenum-basedstructure. - Supports
nestedobjects and arrays. - Provides efficient traversal without allocations beyond the initial parse.
- Designed for maximum
speedand minimal memory footprint.
CrateInfo
High-performance functions to fetch and interact with structured Crates.io API metadata.
Overview
CrateInfo provides high-level utilities for retrieving and processing crate metadata from crates.io. It simplifies fetching crate details, parsing JSON responses, and formatting large numeric data into human-readable strings. Built on top of the lightweight Http client and Json parser, it offers dependency-free, fast, and reliable access to crate information.
Key Features
- Efficient Data Fetching: Uses the internal
Httpclient for network requests. - Dependency-Free JSON Parsing: Leverages the
Jsonenum for minimal overhead. - Readable Data Formatting: Converts large numbers into compact formats (
k,M). - Structured Metadata: Provides comprehensive crate statistics and details.
Usage Examples
Fetching Crate Metadata
use crate_data;
// -----------------------------------
// Latest: v1.5.0
// Versions: 55
// Downloads: 56.3k
// total_downloads: 56326
// License: MIT OR Apache-2.0
// Created: 2021-02-26T19:02:59.116360Z
// Updated: 2025-10-16T20:18:58.196131Z
// -----------------------------------
Formatting Large Numbers
use format_number;
Features
- Fetches detailed crate
infofrom crates.io - Parses and extracts specific
metadatafields - Formats large numbers into human-readable strings
- Easy integration with existing Rust projects
Internal Architecture
- Uses the internal
Httpclient for network requests. - Parses JSON responses with a dependency-free
Jsonenum. - Handles common JSON structures returned by the crates.io API.
- Formats and presents data in a user-friendly manner.
ENV
Panic-free utilities for safely loading and managing environment variables.
Overview
ENV provides safe, straightforward functions to load environment variables from .env files and retrieve them with optional fallbacks or parsing. Designed to be panic-free, it ensures robust environment management suitable for both development and production environments.
Key Features
- Non-panicking environment loading: Safely loads
.envfiles without panics. - Flexible retrieval: Fetch environment variables with or without defaults.
- Typed parsing: Convert environment variables into desired types.
- Automatic initialization: Internal
.envloading for convenience. - Error transparency: Returns explicit errors for missing or invalid variables.
Usage Examples
Initializing Environment Variables
use init_env;
Fetching a Required Variable
use get_env;
match get_env
Fetching with Default Value
use get_env_or;
let port = get_env_or;
println!;
Parsing Environment Variables into Types
use get_env_parse;
let port: u16 = get_env_parse.unwrap_or;
let debug_mode: bool = get_env_parse.unwrap_or;
Fetching and Parsing with Default
use get_env_parse_or;
let max_connections = get_env_parse_or;
Features
- Load environment variables from
.envfiles safely - Retrieve variables with optional defaults
- Parse variables into common types (
u16,bool, etc.) - No panics; returns errors explicitly
- Internal
.envloading for convenience
Internal Architecture
- Uses
dotenvyfor loading.envfiles. - Wraps environment variable access with error handling.
- Provides parsing into any type that implements
FromStr. - Designed for safe, panic-free operation.
License
This project is licensed under the MIT License or Apache 2.0 License.nnector, no other dependencies are required.