1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
//! # Crate Checker
//!
//! Rust crate information retrieval tool that provides both a powerful
//! CLI interface and a library API for querying crates.io.
//!
//! ## Features
//!
//! - **Crate existence checking** - Quickly verify if a crate exists
//! - **Version information** - Get detailed version history and metadata
//! - **Dependency analysis** - Explore dependencies and their relationships
//! - **Download statistics** - Access download metrics and trends
//! - **Batch processing** - Process multiple crates efficiently
//! - **REST API server** - Run as an HTTP server for integration
//! - **Multiple output formats** - JSON, YAML, Table, CSV, and compact
//! - **Async/concurrent** - Built on Tokio for excellent performance
//!
//! ## Quick Start
//!
//! Add to your `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! crate-checker = "0.1.0"
//! ```
//!
//! ## Library Usage
//!
//! ### Basic Example
//!
//! ```rust,no_run
//! use crate_checker::{CrateClient, Result};
//!
//! #[tokio::main]
//! async fn main() -> Result<()> {
//! // Create a client with default settings
//! let client = CrateClient::new();
//!
//! // Check if a crate exists
//! let exists = client.crate_exists("serde").await?;
//! println!("Serde exists: {}", exists);
//!
//! // Get detailed information
//! let info = client.get_crate_info("tokio").await?;
//! println!("Tokio version: {}", info.newest_version);
//! println!("Downloads: {}", info.downloads);
//!
//! Ok(())
//! }
//! ```
//!
//! ### Custom Client Configuration
//!
//! ```rust,no_run
//! use crate_checker::{CrateClient, Result};
//! use std::time::Duration;
//!
//! # async fn example() -> Result<()> {
//! let client = CrateClient::builder()
//! .base_url("https://crates.io/api/v1")
//! .timeout(Duration::from_secs(30))
//! .user_agent("my-app/1.0")
//! .build()?;
//! # Ok(())
//! # }
//! ```
//!
//! ### Batch Processing
//!
//! ```rust,no_run
//! use crate_checker::{CrateClient, Result};
//! use std::collections::HashMap;
//!
//! # async fn example() -> Result<()> {
//! let client = CrateClient::new();
//!
//! // Process multiple crates with specific versions
//! let mut versions = HashMap::new();
//! versions.insert("serde".to_string(), "0.1.0".to_string());
//! versions.insert("tokio".to_string(), "latest".to_string());
//!
//! let result = client.process_crate_version_map(versions).await?;
//! println!("Processed {} crates", result.total_processed);
//! println!("Successful: {}, Failed: {}", result.successful, result.failed);
//! # Ok(())
//! # }
//! ```
//!
//! ### Error Handling
//!
//! ```rust,no_run
//! use crate_checker::{CrateClient, CrateCheckerError, Result};
//!
//! # async fn example() -> Result<()> {
//! let client = CrateClient::new();
//!
//! match client.get_crate_info("unknown-crate").await {
//! Ok(info) => println!("Found: {}", info.name),
//! Err(CrateCheckerError::CrateNotFound(name)) => {
//! println!("Crate '{}' not found", name);
//! }
//! Err(e) if e.is_recoverable() => {
//! println!("Temporary error, can retry: {}", e);
//! }
//! Err(e) => {
//! println!("Error: {}", e.user_message());
//! }
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ## CLI Usage
//!
//! The crate-checker binary provides a comprehensive command-line interface:
//!
//! ```bash
//! # Check if a crate exists
//! crate-checker check serde
//!
//! # Get detailed information with dependencies
//! crate-checker info tokio --deps --stats
//!
//! # Search for crates
//! crate-checker search "http client" --limit 10
//!
//! # Check multiple crates
//! crate-checker check-multiple serde tokio reqwest
//!
//! # Start API server
//! crate-checker server --port 8080
//! ```
//!
//! ## API Server
//!
//! Run crate-checker as an HTTP server:
//!
//! ```bash
//! crate-checker server --port 8080 --cors
//! ```
//!
//! Available endpoints:
//! - `GET /health` - Health check
//! - `GET /api/crates/{name}` - Get crate info
//! - `GET /api/search?q={query}` - Search crates
//! - `POST /api/batch` - Batch processing
//!
//! ## Configuration
//!
//! Configure via file (`crate-checker.toml`) or environment variables:
//!
//! ```toml
//! [server]
//! port = 8080
//! host = "0.0.0.0"
//!
//! [cache]
//! enabled = true
//! ttl_seconds = 300
//!
//! [crates_io]
//! timeout_seconds = 30
//! ```
//!
//! Environment variables: `CRATE_CHECKER__SECTION__KEY`
//!
//! ## Performance Tips
//!
//! - Enable caching to reduce API calls
//! - Use batch operations for multiple crates
//! - Configure appropriate timeouts
//! - Use parallel processing when available
//!
//! ## Examples
//!
//! See the `examples/` directory for more usage patterns:
//! - `basic_usage.rs` - Simple API usage
//! - `batch_processing.rs` - Batch operations
//! - `monitor_updates.rs` - Version monitoring
//! - `custom_client.rs` - Advanced configuration
// Re-export commonly used items at the crate root for convenience
pub use ;
pub use ;
pub use ;
// Re-export configuration types for server users
pub use ;
/// Default crates.io API base URL
pub const DEFAULT_API_URL: &str = "https://crates.io/api/v1";
/// Default user agent for requests
pub const DEFAULT_USER_AGENT: &str = "crate-checker/0.1.0";
/// Default request timeout in seconds
pub const DEFAULT_TIMEOUT_SECS: u64 = 30;
/// Default server port
pub const DEFAULT_SERVER_PORT: u16 = 3000;
/// Library version
pub const VERSION: &str = env!;
/// Library name
pub const NAME: &str = env!;