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 message_url(self, url: impl Into<String>) -> Self
pub fn message_url(self, url: impl Into<String>) -> Self
Set a URL to fetch an update message from.
When an update is available, the checker will make a separate HTTP request
to this URL and include the response as DetailedUpdateInfo::message. The URL
should serve plain text.
The fetch is best-effort: if it fails, the update check still succeeds
with message set to None. The message is trimmed and truncated to 4KB.
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.
For additional metadata (update messages, response body), use
check_detailed instead.
§Stability
In 2.0, check and check_detailed will likely be combined into a
single method returning DetailedUpdateInfo (with UpdateInfo removed).
§Errors
Returns an error if the crate name is invalid, the HTTP request fails, the response cannot be parsed, or version comparison fails.
Sourcepub fn check_detailed(&self) -> Result<Option<DetailedUpdateInfo>, Error>
pub fn check_detailed(&self) -> Result<Option<DetailedUpdateInfo>, Error>
Check for updates with extended metadata.
Like check, but returns DetailedUpdateInfo which
includes an optional author message and (with the response-body
feature) the raw crates.io response.
§Stability
In 2.0, check and check_detailed will likely be combined into a
single method returning DetailedUpdateInfo (with UpdateInfo removed).
§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