Struct UpdateInformer

Source
pub struct UpdateInformer<R: Registry, N: AsRef<str>, V: AsRef<str>, H: HttpClient = DefaultHttpClient> { /* private fields */ }
Expand description

Checks for a new version on Crates.io, GitHub, Npm or PyPi.

A cache file handled by the instance throttles the number of actual update checks, or you can opt in to manage this yourself.

Implementations§

Source§

impl<R, N, V, H> UpdateInformer<R, N, V, H>
where R: Registry, N: AsRef<str>, V: AsRef<str>, H: HttpClient,

Source

pub fn interval(self, interval: Duration) -> Self

Sets the interval of how often to check for a new version.

§Arguments
  • interval - The Duration after an actual update check during which a subsequent check will be skipped. 24 hours by default. This is implemented using a cache file. Specify Duration::ZERO to work without a cache file and unconditionally perform the update check.
§Examples
use std::time::Duration;
use update_informer::{registry, Check};

const EVERY_HOUR: Duration = Duration::from_secs(60 * 60);

let informer = update_informer::new(registry::Crates, "crate_name", "0.1.0").interval(EVERY_HOUR);
let _ = informer.check_version(); // The check will start only after an hour
Source

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

Sets a request timeout.

§Arguments
  • timeout - A request timeout. By default, it is 5 seconds.
§Examples
use std::time::Duration;
use update_informer::{registry, Check};

const THIRTY_SECONDS: Duration = Duration::from_secs(30);

let informer = update_informer::new(registry::Crates, "crate_name", "0.1.0").timeout(THIRTY_SECONDS);
let _ = informer.check_version();
Source

pub fn http_client<C: HttpClient>( self, http_client: C, ) -> UpdateInformer<R, N, V, C>

Sets an HTTP client to send request to the registry.

§Arguments
  • http_client - A type that implements the HttpClient trait.
§Examples
use isahc::ReadResponseExt;
use std::time::Duration;
use serde::de::DeserializeOwned;
use update_informer::{http_client::{HeaderMap, HttpClient}, registry, Check};

struct YourOwnHttpClient;

impl HttpClient for YourOwnHttpClient {
    fn get<T: DeserializeOwned>(
        url: &str,
        _timeout: Duration,
        _headers: HeaderMap,
    ) -> update_informer::Result<T> {
        let json = isahc::get(url)?.json()?;
        Ok(json)
    }
}

let informer = update_informer::new(registry::Crates, "crate_name", "0.1.0").http_client(YourOwnHttpClient);
let _ = informer.check_version();

Trait Implementations§

Source§

impl<R, N, V, H> Check for UpdateInformer<R, N, V, H>
where R: Registry, N: AsRef<str>, V: AsRef<str>, H: HttpClient,

Source§

fn check_version(self) -> Result<Option<Version>>

Checks for a new version in the registry.

In case of a non-zero interval(), this will create or access a cache file.

§Examples

To check for a new version on Crates.io:

use update_informer::{registry, Check};

let informer = update_informer::new(registry::Crates, "crate_name", "0.1.0");
let _ = informer.check_version();

Auto Trait Implementations§

§

impl<R, N, V, H> Freeze for UpdateInformer<R, N, V, H>
where R: Freeze, N: Freeze, V: Freeze, H: Freeze,

§

impl<R, N, V, H> RefUnwindSafe for UpdateInformer<R, N, V, H>

§

impl<R, N, V, H> Send for UpdateInformer<R, N, V, H>
where R: Send, N: Send, V: Send, H: Send,

§

impl<R, N, V, H> Sync for UpdateInformer<R, N, V, H>
where R: Sync, N: Sync, V: Sync, H: Sync,

§

impl<R, N, V, H> Unpin for UpdateInformer<R, N, V, H>
where R: Unpin, N: Unpin, V: Unpin, H: Unpin,

§

impl<R, N, V, H> UnwindSafe for UpdateInformer<R, N, V, H>

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> 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, 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.
Source§

impl<T> ErasedDestructor for T
where T: 'static,