You've already forked rust-users
mirror of
https://github.com/uutils/rust-users.git
synced 2026-06-10 15:48:37 -07:00
Add a full UsersCache constructor
This commit is contained in:
+14
-1
@@ -68,7 +68,7 @@ use std::collections::hash_map::Entry::{Occupied, Vacant};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
use base::{User, Group};
|
||||
use base::{User, Group, AllUsers};
|
||||
use traits::{Users, Groups};
|
||||
|
||||
|
||||
@@ -124,6 +124,19 @@ impl UsersCache {
|
||||
pub fn new() -> UsersCache {
|
||||
UsersCache::default()
|
||||
}
|
||||
|
||||
pub unsafe fn with_all_users() -> UsersCache {
|
||||
let cache = UsersCache::new();
|
||||
|
||||
for user in unsafe { AllUsers::new() } {
|
||||
let uid = user.uid();
|
||||
let user_arc = Arc::new(user);
|
||||
cache.users.forward.borrow_mut().insert(uid, Some(user_arc.clone()));
|
||||
cache.users.backward.borrow_mut().insert(user_arc.name_arc.clone(), Some(uid));
|
||||
}
|
||||
|
||||
cache
|
||||
}
|
||||
}
|
||||
|
||||
impl Users for UsersCache {
|
||||
|
||||
Reference in New Issue
Block a user