self_update_extras/lib.rs
1//! Self-updating support for CLI binaries.
2//!
3//! This crate provides two composable wrappers around any type implementing
4//! [`self_update::update::ReleaseUpdate`], each exposed through a builder in
5//! the style of `self_update`'s own backends:
6//!
7//! - [`throttle::Update`] limits how often update checks run by recording the
8//! time of the last check in a throttle file in the system temp directory.
9//! - [`restart::Update`] re-executes the process with the freshly installed
10//! binary after a successful update, using a guard environment variable to
11//! prevent restart loops.
12//!
13//! Both wrappers implement `ReleaseUpdate` themselves and their builders
14//! produce a `Box<dyn ReleaseUpdate>`, so they can be layered over a backend
15//! (or over each other) and used anywhere a `ReleaseUpdate` is expected.
16//!
17//! # Example
18//!
19//! ```ignore
20//! use self_update_extras::{restart, throttle};
21//! use self_update::backends::github;
22//! use self_update::update::ReleaseUpdate;
23//! use std::time::Duration;
24//!
25//! // Any `ReleaseUpdate` implementation, e.g. a self_update GitHub backend.
26//! let backend = github::Update::configure().build()?;
27//!
28//! let throttled = throttle::Update::configure()
29//! .release_update(backend)
30//! .throttle_window(Duration::from_secs(15 * 60))
31//! .build()?;
32//!
33//! let updater = restart::Update::configure()
34//! .release_update(throttled)
35//! .guard_env("MY_APP_AUTO_UPDATED")
36//! .build()?;
37//!
38//! let status = updater.update()?;
39//! ```
40
41pub mod restart;
42pub mod throttle;
43
44#[cfg(test)]
45mod test_support;