pub trait Launcher {
// Provided methods
fn resume_args(&self, state_json: &str) -> Vec<OsString> { ... }
fn extra_args(&self) -> Vec<OsString> { ... }
fn extra_envs(&self) -> Vec<(OsString, OsString)> { ... }
fn launch(&self, app_path: &Path, state: &UpdateState) -> Result<(), Error> { ... }
fn detach(&self, cmd: &mut Command) { ... }
fn spawn(&self, cmd: Command) -> Result<(), Error> { ... }
}Expand description
Launches the application binary to drive the next phase of an update.
Every method has a default implementation, so the simplest custom launcher is
an empty impl Launcher for MyLauncher {} (equivalent to a bare
DefaultLauncher). Customise as much or as little as you need:
- override
resume_argsto change how the update state is handed to the relaunched process (e.g. via a sub-command rather than the defaultRESUME_FLAG); - override
extra_args/extra_envsto add your own arguments / environment variables to the relaunch (DefaultLauncherexposes builders for these, so you usually don’t need a custom launcher just for that); - override
launchfor complete control over the relaunch command, orspawnto change how the child is started.
Install a custom launcher with
UpdateManager::with_launcher.
Provided Methods§
Sourcefn resume_args(&self, state_json: &str) -> Vec<OsString>
fn resume_args(&self, state_json: &str) -> Vec<OsString>
The arguments that carry the serialized resume state_json to the
relaunched process.
The default passes the library’s RESUME_FLAG
followed by the JSON, which a consuming main() detects (before any other
argument parsing) and forwards to
resume_from_arg. Override it to
use a different convention — for example handing the state to a
sub-command:
use std::ffi::OsString;
use update_rs::Launcher;
struct SubcommandLauncher;
impl Launcher for SubcommandLauncher {
fn resume_args(&self, state_json: &str) -> Vec<OsString> {
vec!["update".into(), "--state".into(), state_json.into()]
}
}Sourcefn extra_args(&self) -> Vec<OsString>
fn extra_args(&self) -> Vec<OsString>
Extra command-line arguments to append to the relaunch command, after the
resume_args.
The default adds none; DefaultLauncher returns the arguments configured
via DefaultLauncher::with_arg.
Sourcefn extra_envs(&self) -> Vec<(OsString, OsString)>
fn extra_envs(&self) -> Vec<(OsString, OsString)>
Extra environment variables to set on the relaunched process (added to, not replacing, the inherited environment).
The default sets none; DefaultLauncher returns the variables configured
via DefaultLauncher::with_env.
Sourcefn launch(&self, app_path: &Path, state: &UpdateState) -> Result<(), Error>
fn launch(&self, app_path: &Path, state: &UpdateState) -> Result<(), Error>
Build and spawn the command that relaunches app_path to continue the
update with state.
The default builds app_path <resume_args> <extra_args> with the
extra_envs and the platform
detach flags, then spawns it.
Override this for complete control over the relaunch command, reusing
resume_args, detach and
spawn as needed.
Sourcefn detach(&self, cmd: &mut Command)
fn detach(&self, cmd: &mut Command)
Apply the platform-specific flags that detach the relaunched process from
the current console so it survives the parent exiting (a detached process
in its own group on Windows). A no-op on non-Windows platforms. Exposed so
custom launch implementations can reuse it.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".