system_shutdown provides a cross platform way to shut down, reboot or log out operations.
Supported platforms: Linux, Windows and MacOS.
The example below shows how to shut down the machine:
extern crate system_shutdown;
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.
Add this to your Cargo.toml:
[dependencies]
system_shutdown = "3.0.0"and this to your crate root:
extern crate system_shutdown;Pull Requests and Issues are welcome!
system_shutdown is licensed under either of the following, at your option:
- Apache License 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)