Skip to main content

Crate self_update_extras

Crate self_update_extras 

Source
Expand description

Self-updating support for CLI binaries.

This crate provides two composable wrappers around any type implementing self_update::update::ReleaseUpdate, each exposed through a builder in the style of self_update’s own backends:

  • throttle::Update limits how often update checks run by recording the time of the last check in a throttle file in the system temp directory.
  • restart::Update re-executes the process with the freshly installed binary after a successful update, using a guard environment variable to prevent restart loops.

Both wrappers implement ReleaseUpdate themselves and their builders produce a Box<dyn ReleaseUpdate>, so they can be layered over a backend (or over each other) and used anywhere a ReleaseUpdate is expected.

§Example

use self_update_extras::{restart, throttle};
use self_update::backends::github;
use self_update::update::ReleaseUpdate;
use std::time::Duration;

// Any `ReleaseUpdate` implementation, e.g. a self_update GitHub backend.
let backend = github::Update::configure().build()?;

let throttled = throttle::Update::configure()
    .release_update(backend)
    .throttle_window(Duration::from_secs(15 * 60))
    .build()?;

let updater = restart::Update::configure()
    .release_update(throttled)
    .guard_env("MY_APP_AUTO_UPDATED")
    .build()?;

let status = updater.update()?;

Modules§

restart
Restart wrapper: re-executes the process after a successful update.
throttle
Throttle wrapper: limits how often update checks run.