pub trait UserExt: Debug {
    fn id(&self) -> &Uid;
    fn group_id(&self) -> Gid;
    fn name(&self) -> &str;
    fn groups(&self) -> &[String];
}
Expand description

Getting information for a user.

It is returned from SystemExt::users.

use sysinfo::{System, SystemExt, UserExt};

let mut s = System::new_all();
for user in s.users() {
    println!("{} is in {} groups", user.name(), user.groups().len());
}

Required Methods

Return the user id of the user.

use sysinfo::{System, SystemExt, UserExt};

let mut s = System::new_all();
for user in s.users() {
    println!("{:?}", *user.id());
}

Return the group id of the user.

NOTE - On Windows, this value defaults to 0. Windows doesn’t have a username specific group assigned to the user. They do however have unique Security Identifiers made up of various Components. Pieces of the SID may be a candidate for this field, but it doesn’t map well to a single group id.

use sysinfo::{System, SystemExt, UserExt};

let mut s = System::new_all();
for user in s.users() {
    println!("{}", *user.group_id());
}

Returns the name of the user.

use sysinfo::{System, SystemExt, UserExt};

let mut s = System::new_all();
for user in s.users() {
    println!("{}", user.name());
}

Returns the groups of the user.

use sysinfo::{System, SystemExt, UserExt};

let mut s = System::new_all();
for user in s.users() {
    println!("{} is in {:?}", user.name(), user.groups());
}

Implementors