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>
impl<R, N, V, H> UpdateInformer<R, N, V, H>
Sourcepub fn interval(self, interval: Duration) -> Self
pub fn interval(self, interval: Duration) -> Self
Sets the interval of how often to check for a new version.
§Arguments
interval- TheDurationafter an actual update check during which a subsequent check will be skipped. 24 hours by default. This is implemented using a cache file. SpecifyDuration::ZEROto 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 hourSourcepub fn timeout(self, timeout: Duration) -> Self
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();Sourcepub fn http_client<C: HttpClient>(
self,
http_client: C,
) -> UpdateInformer<R, N, V, C>
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 theHttpClienttrait.
§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>
impl<R, N, V, H> Check for UpdateInformer<R, N, V, H>
Source§fn check_version(self) -> Result<Option<Version>>
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>
impl<R, N, V, H> RefUnwindSafe for UpdateInformer<R, N, V, H>
impl<R, N, V, H> Send for UpdateInformer<R, N, V, H>
impl<R, N, V, H> Sync for UpdateInformer<R, N, V, H>
impl<R, N, V, H> Unpin for UpdateInformer<R, N, V, H>
impl<R, N, V, H> UnwindSafe for UpdateInformer<R, N, V, H>
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