You've already forked rust-users
mirror of
https://github.com/uutils/rust-users.git
synced 2026-06-10 15:48:37 -07:00
77eefe0176
It's more descriptive to call it a cache when there are functions that do all the *actual* OS users stuff separately now. Similarly, we may as well call its constructor 'new' instead of 'empty_cache', because it's obvious that it's a cache now.
25 lines
755 B
Rust
25 lines
755 B
Rust
extern crate users;
|
|
use users::{Users, Groups, UsersCache};
|
|
|
|
fn main() {
|
|
let cache = UsersCache::new();
|
|
|
|
let current_uid = cache.get_current_uid();
|
|
println!("Your UID is {}", current_uid);
|
|
|
|
let you = cache.get_user_by_uid(current_uid).expect("No entry for current user!");
|
|
println!("Your username is {}", you.name);
|
|
|
|
let primary_group = cache.get_group_by_gid(you.primary_group).expect("No entry for your primary group!");
|
|
println!("Your primary group has ID {} and name {}", primary_group.gid, primary_group.name);
|
|
|
|
if primary_group.members.is_empty() {
|
|
println!("There are no other members of that group.");
|
|
}
|
|
else {
|
|
for username in primary_group.members.iter() {
|
|
println!("User {} is also a member of that group.", username);
|
|
}
|
|
}
|
|
}
|