diff --git a/src/user_management/user.rs b/src/user_management/user.rs index 0b96f77..baa139a 100644 --- a/src/user_management/user.rs +++ b/src/user_management/user.rs @@ -375,6 +375,23 @@ impl RegisteredUser { pub fn has_password(&self) -> bool { self.inner.pass_hash.is_some() } + + /// Get an immutable reference to the data associated with this user + pub fn data(&self) -> &UserData { + &self.inner.data + } + + /// Get a mutable reference to the data associated with this user + /// + /// This automatically flags the user data as needing to be saved to the database, + /// which automatically performs the action when this user falls out of scope. If + /// need be, you can push these changes to the database sooner by calling [`save()`] + /// + /// [`save()`]: Self::save() + pub fn mut_data(&mut self) -> &mut UserData { + self.has_changed = true; + &mut self.inner.data + } } impl std::ops::Drop for RegisteredUser { @@ -389,15 +406,12 @@ impl std::ops::Drop for RegisteredUser AsRef for RegisteredUser { fn as_ref(&self) -> &UserData { - &self.inner.data + self.data() } } impl AsMut for RegisteredUser { - /// NOTE: Changes made to the user data won't be persisted until RegisteredUser::save - /// is called fn as_mut(&mut self) -> &mut UserData { - self.has_changed = true; - &mut self.inner.data + self.mut_data() } }