Function is_root::is_root

source ·
pub fn is_root() -> bool
Expand description

Returns true if user is root; false otherwise

use is_root::is_root;

if is_root() {
    println!("Doing something dangerous")
} else {
    eprintln!("Run me as root")
}
Examples found in repository?
examples/amiroot.rs (line 4)
3
4
5
6
7
8
9
fn main() {
    if is_root() {
        println!("You are root");
    } else {
        println!("You are not root")
    }
}