Crate system_shutdown

Source
Expand description

system_shutdown provides a cross platform way to shut down, reboot or log out operations.

Supported platforms: Linux, Windows and macOS.

§Example

The example below shows how to shut down the machine:

use system_shutdown::shutdown;

fn main() {
    match shutdown() {
        Ok(_) => println!("Shutting down, bye!"),
        Err(error) => eprintln!("Failed to shut down: {}", error),
    }
}

In most of the systems it does not requires the user to be root/admin.

Functions§

force_logout
Calls the OS-specific function to force to log out the user.
force_reboot
Calls the OS-specific function to force to reboot the machine.
force_shutdown
Calls the OS-specific function to force to shut down the machine.
hibernate
Calls the OS-specific function to hibernate the machine.
logout
Calls the OS-specific function to log out the user.
reboot
Calls the OS-specific function to reboot the machine.
shutdown
Calls the OS-specific function to shut down the machine.
sleep
Calls the OS-specific function to put the machine to sleep.

Type Aliases§

ShutdownResult
A specialized Result type for shut down, reboot and log out operations.