Files
rust-users/examples/example.rs
T

25 lines
762 B
Rust
Raw Normal View History

2014-12-12 10:36:17 +00:00
extern crate users;
2016-01-26 19:17:24 +00:00
use users::{Users, Groups, UsersCache};
2014-12-12 10:36:17 +00:00
fn main() {
2016-01-26 19:17:24 +00:00
let cache = UsersCache::new();
2014-12-12 10:36:17 +00:00
let current_uid = cache.get_current_uid();
println!("Your UID is {}", current_uid);
2014-12-12 10:36:17 +00:00
let you = cache.get_user_by_uid(current_uid).expect("No entry for current user!");
2016-01-28 15:04:22 +00:00
println!("Your username is {}", you.name());
2016-01-28 15:04:22 +00:00
let primary_group = cache.get_group_by_gid(you.primary_group_id()).expect("No entry for your primary group!");
2014-12-12 10:36:17 +00:00
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);
}
}
}