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 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 Err if the check failed.
§Errors
Returns an error if 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
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for UpdateChecker
impl RefUnwindSafe for UpdateChecker
impl Send for UpdateChecker
impl Sync for UpdateChecker
impl Unpin for UpdateChecker
impl UnwindSafe for UpdateChecker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more