|
|
|
@ -1,27 +1,13 @@ |
|
|
|
use std::collections;
|
|
|
|
use std::error;
|
|
|
|
use std::fmt;
|
|
|
|
|
|
|
|
use thiserror::Error;
|
|
|
|
|
|
|
|
use solstice_proto::{User, UserStatus};
|
|
|
|
|
|
|
|
/// The error returned when a user name was not found in the user map.
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct UserNotFoundError {
|
|
|
|
/// The name of the user that wasn't found.
|
|
|
|
user_name: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for UserNotFoundError {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "user \"{}\" not found", self.user_name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl error::Error for UserNotFoundError {
|
|
|
|
fn description(&self) -> &str {
|
|
|
|
"user not found"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#[derive(Debug, Error)]
|
|
|
|
#[error("user {0:?} not found")]
|
|
|
|
pub struct UserNotFoundError(String);
|
|
|
|
|
|
|
|
/// Contains the mapping from user names to user data and provides a clean
|
|
|
|
/// interface to interact with it.
|
|
|
|
@ -54,9 +40,7 @@ impl UserMap { |
|
|
|
) -> Result<&mut User, UserNotFoundError> {
|
|
|
|
match self.map.get_mut(user_name) {
|
|
|
|
Some(user) => Ok(user),
|
|
|
|
None => Err(UserNotFoundError {
|
|
|
|
user_name: user_name.to_string(),
|
|
|
|
}),
|
|
|
|
None => Err(UserNotFoundError(user_name.to_string())),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|