A minimal, lightweight crate update checker for Rust CLI applications.
Existing update checker crates add significant binary bloat:
| Crate | Binary Impact |
|---|---|
| tiny-update-check | ~0.5MB |
| update-informer | ~1.4MB |
| updates | ~1.8MB |
This crate achieves minimal size by:
- Using
native-tls(system TLS) instead of bundling rustls - Minimal JSON parsing (string search instead of serde)
- Simple file-based caching
[dependencies]
tiny-update-check = "0.1"For pure-Rust TLS (larger binary, but better cross-compilation):
[dependencies]
tiny-update-check = { version = "0.1", default-features = false, features = ["rustls"] }use tiny_update_check::check;
fn main() {
// Check at end of your CLI's main function
if let Ok(Some(update)) = check(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")) {
eprintln!("Update available: {} -> {}", update.current, update.latest);
}
}use tiny_update_check::UpdateChecker;
use std::time::Duration;
fn main() {
let checker = UpdateChecker::new(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"))
.cache_duration(Duration::from_secs(60 * 60)) // 1 hour cache
.timeout(Duration::from_secs(10)); // 10 second timeout
match checker.check() {
Ok(Some(update)) => {
eprintln!("New version {} available!", update.latest);
eprintln!("You have version {}", update.current);
}
Ok(None) => {} // Already on latest
Err(e) => {
// Silently ignore errors - don't disrupt the user's workflow
log::debug!("Update check failed: {}", e);
}
}
}use tiny_update_check::UpdateChecker;
use std::time::Duration;
let checker = UpdateChecker::new("my-crate", "1.0.0")
.cache_duration(Duration::ZERO); // Always fetch freshnative-tls(default) - Uses system TLS libraries, smaller binaryrustls- Pure Rust TLS, no system dependencies
- Checks cache file (
~/.cache/<crate>-update-check) for recent version info - If cache is stale (default: 24 hours), queries crates.io API
- Compares versions using semver
- Returns
Some(UpdateInfo)if newer version exists
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT License (LICENSE-MIT)
at your option.