Skip to main content

UpdateChecker

Struct UpdateChecker 

Source
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

Source

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.io
  • current_version - The currently running version (typically from env!("CARGO_PKG_VERSION"))
Source

pub const fn cache_duration(self, duration: Duration) -> Self

Set the cache duration. Defaults to 24 hours.

Set to Duration::ZERO to disable caching.

Source

pub const fn timeout(self, timeout: Duration) -> Self

Set the HTTP request timeout. Defaults to 5 seconds.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> UpdateChecker

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for UpdateChecker

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.