Added ability to iterate through users in the database

This commit is contained in:
Emii Tatsuo 2020-11-27 18:01:49 -05:00
parent 1e5e4c8731
commit 6c3ae626e9
Signed by: Emi
GPG key ID: 68FAB2E2E6DFC98B

View file

@ -83,6 +83,29 @@ impl UserManager {
}
}
/// Produce a list of all users in the database
///
/// # Panics
/// An panics if there is an error reading from the database or if data recieved from
/// the database is corrupt
pub fn all_users<UserData>(
&self,
) -> Vec<RegisteredUser<UserData>>
where
UserData: Serialize + DeserializeOwned
{
self.users.iter()
.map(|result| {
let (username, bytes) = result.expect("Failed to connect to database");
let inner: PartialUser<UserData> = bincode::deserialize_from(bytes.as_ref())
.expect("Received malformed data from database");
let username = String::from_utf8(username.to_vec())
.expect("Malformed username in database");
RegisteredUser::new(username, None, self.clone(), inner)
})
.collect()
}
/// Attempt to determine the user who sent a request based on the certificate.
///
/// # Errors