Trait sysinfo::UserExt

source ·
pub trait UserExt: Debug {
    // Required methods
    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§

source

fn id(&self) -> &Uid

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());
}
source

fn group_id(&self) -> Gid

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());
}
source

fn name(&self) -> &str

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());
}
source

fn groups(&self) -> &[String]

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§