pub struct UpdateChecker { /* private fields */ }Expand description
A lightweight update checker for crates.io.
§Example
use tiny_update_check::UpdateChecker;
let checker = UpdateChecker::new("my-crate", "1.0.0");
match checker.check() {
Ok(Some(update)) => println!("Update available: {}", update.latest),
Ok(None) => println!("Already on latest version"),
Err(e) => eprintln!("Failed to check for updates: {}", e),
}Implementations§
Source§impl UpdateChecker
impl UpdateChecker
Sourcepub fn new(
crate_name: impl Into<String>,
current_version: impl Into<String>,
) -> Self
pub fn new( crate_name: impl Into<String>, current_version: impl Into<String>, ) -> Self
Create a new update checker for the given crate.
§Arguments
crate_name- The name of your crate on crates.iocurrent_version- The currently running version (typically fromenv!("CARGO_PKG_VERSION"))
Sourcepub const fn cache_duration(self, duration: Duration) -> Self
pub const fn cache_duration(self, duration: Duration) -> Self
Set the cache duration. Defaults to 24 hours.
Set to Duration::ZERO to disable caching.
Sourcepub const fn timeout(self, timeout: Duration) -> Self
pub const fn timeout(self, timeout: Duration) -> Self
Set the HTTP request timeout. Defaults to 5 seconds.
Sourcepub fn cache_dir(self, dir: Option<PathBuf>) -> Self
pub fn cache_dir(self, dir: Option<PathBuf>) -> Self
Set a custom cache directory. Defaults to system cache directory.
Set to None to disable caching.
Sourcepub const fn include_prerelease(self, include: bool) -> Self
pub const fn include_prerelease(self, include: bool) -> Self
Include pre-release versions in update checks. Defaults to false.
When false (the default), versions like 2.0.0-alpha.1 or 2.0.0-beta
will not be reported as available updates. Set to true to receive
notifications about pre-release versions.
Sourcepub fn check(&self) -> Result<Option<UpdateInfo>, Error>
pub fn check(&self) -> Result<Option<UpdateInfo>, Error>
Check for updates.
Returns Ok(Some(UpdateInfo)) if a newer version is available,
Ok(None) if already on the latest version (or if DO_NOT_TRACK=1 is set
and the do-not-track feature is enabled),
or Err if the check failed.
§Errors
Returns an error if the crate name is invalid, the HTTP request fails, the response cannot be parsed, or version comparison fails.
Trait Implementations§
Source§impl Clone for UpdateChecker
impl Clone for UpdateChecker
Source§fn clone(&self) -> UpdateChecker
fn clone(&self) -> UpdateChecker
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more