Expand description
Safe blocking bindings to the Windows Restart Manager (rstrtmgr.dll).
A primary RestartSession owns shutdown, restart, filter, and
cancellation capabilities. A secondary JoinedSession can only register
and inspect resources, making a role violation impossible to express.
§Example
use restart_manager::{RestartSession, ShutdownOptions};
let mut session = RestartSession::new()?;
session.register_files([r"C:\some\locked\file.dll"])?;
let report = session.affected_applications()?;
for application in &report {
println!("locked by: {:?}", application.display_name());
}
let pending = session.shutdown_with_options(ShutdownOptions::default());
let can_update = pending.shutdown_outcome().is_success();
if can_update {
// Replace or update the registered files here.
}
let completion = pending.restart();
let outcome = completion.outcome().clone();
completion.end()?;
outcome.shutdown_outcome().clone().into_result()?;
outcome
.restart_outcome()
.expect("restart was attempted")
.clone()
.into_result()?;Relative file and executable paths are made absolute, but this crate never checks existence or canonicalizes them. Restart Manager does not support registering directories. Forced shutdown is opt-in and can lose target application data. Restart is only possible for services and applications that registered for restart.
Progress callbacks use a process-global native callback slot because the
Windows API supplies no context pointer. Concurrent callback-bearing calls
fail immediately with ErrorKind::CallbackInUse. A callback panic is
contained at the FFI boundary and resumed after Windows returns.
§Platform support
All domain and session types are available on every target. Pure input
validation behaves identically everywhere; operations that require Windows
return ErrorKind::UnsupportedPlatform.
§Typestate guarantees
A joined installer cannot query or control the primary workflow:
fn invalid(joined: &mut restart_manager::JoinedSession) {
let _ = joined.affected_applications();
}Restart is not available before a shutdown attempt:
fn invalid(session: restart_manager::RestartSession) {
let _ = session.restart();
}A pending recovery state cannot register resources, manipulate filters, or end the native session:
fn invalid(mut pending: restart_manager::RestartPending) {
let batch = restart_manager::ResourceBatch::new();
let _ = pending.register_resources(&batch);
let _ = pending.end();
}Consuming a state prevents a second operation on the same value:
fn invalid(session: restart_manager::RestartSession) {
let _pending = session.shutdown();
let _ = session.end();
}Modules§
- tokio
- Tokio facade backed by one dedicated standard worker thread per session.
Structs§
- Affected
Application - One application or service using a registered resource.
- Affected
Applications - A reusable affected-application report plus its reboot reasons.
- Application
Restart Options - Command-line arguments and positive restart policies for this application.
- Application
Restart Registration - An exclusive crate-managed lease for the current process registration.
- Application
Status - OR-able history bits from
RM_APP_STATUS. - Cancellation
Handle - A weak,
Send+Synccapability that can cancel a blocking native operation. - Error
- An error returned by the safe Restart Manager API.
- Filter
- One filter returned by
crate::RestartSession::filters. - Filter
Target - The executable, process, or service selected by a filter.
- Joined
Session - A secondary-installer view of an existing session.
- Operation
NotStarted - A consuming operation that failed before native work began.
- Parse
Session KeyError - Error returned when parsing a Restart Manager session key.
- Process
Identity - A process identity made from its ID and creation time.
- Progress
- Progress reported by a blocking shutdown or restart operation.
- Reboot
Reasons - Reasons Windows says a reboot may be required.
- Recovery
Completion - Completed recovery state with retained results and post-operation reporting.
This typestate is
Send. - Recovery
Outcome - Results from the shutdown attempt and the optional restart attempt.
- Resource
Batch - Files, processes, and services to register in one native call.
- Restart
Pending - The state entered after any shutdown attempt.
- Restart
Session - A primary-installer Restart Manager session.
- Session
Key - A validated, 32-character ASCII hexadecimal Restart Manager session key.
- Shutdown
Options - Options accepted by
crate::RestartSession::shutdown_with_options.
Enums§
- Application
Type - The kind of an affected application, corresponding to
RM_APP_TYPE. - Error
Kind - A stable, non-exhaustive classification of failures.
- Filter
Action - The official
RM_FILTER_ACTIONbehavior. - Operation
Outcome - The retained result of one native shutdown or restart attempt.
Type Aliases§
- Result
- Specialised result alias used by this crate.