I have the following type
RwLock<HashMap<String, Arc<RwLock<User>>>>
The idea is to make sure there are no concurrent inserts to the map and to be able to edit the actual entry of the user by unlocking the map in read mode.
In go what i want would look like
struct{
sync.RWMutex
users:map[string]*struct{
sync.RWMutex,
*User
}
}
The main goal is to make the user internally mutable while still being able to use guarantees of rust at compile time.
PS.
These are methods im using to update the original user
pub fn get_mut(&self, uid: &str) -> Option<Arc<RwLock<User>>>
{
if let Some(u) = self.users.read().unwrap().get(uid)
{
Some(u.clone())
}
else
{
None
}
}
pub fn update_token(&self, uid: &str, token: &str)
{
if let Some(u) = self.get_mut(uid)
{
u.write().unwrap().token = token.to_string();
}
}