Add specific methods for getting at UserData
This commit is contained in:
parent
e7cbbd7d91
commit
4a2293ddc6
|
@ -375,6 +375,23 @@ impl<UserData: Serialize + DeserializeOwned> RegisteredUser<UserData> {
|
||||||
pub fn has_password(&self) -> bool {
|
pub fn has_password(&self) -> bool {
|
||||||
self.inner.pass_hash.is_some()
|
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<UserData: Serialize + DeserializeOwned> std::ops::Drop for RegisteredUser<UserData> {
|
impl<UserData: Serialize + DeserializeOwned> std::ops::Drop for RegisteredUser<UserData> {
|
||||||
|
@ -389,15 +406,12 @@ impl<UserData: Serialize + DeserializeOwned> std::ops::Drop for RegisteredUser<U
|
||||||
|
|
||||||
impl<UserData: Serialize + DeserializeOwned> AsRef<UserData> for RegisteredUser<UserData> {
|
impl<UserData: Serialize + DeserializeOwned> AsRef<UserData> for RegisteredUser<UserData> {
|
||||||
fn as_ref(&self) -> &UserData {
|
fn as_ref(&self) -> &UserData {
|
||||||
&self.inner.data
|
self.data()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<UserData: Serialize + DeserializeOwned> AsMut<UserData> for RegisteredUser<UserData> {
|
impl<UserData: Serialize + DeserializeOwned> AsMut<UserData> for RegisteredUser<UserData> {
|
||||||
/// NOTE: Changes made to the user data won't be persisted until RegisteredUser::save
|
|
||||||
/// is called
|
|
||||||
fn as_mut(&mut self) -> &mut UserData {
|
fn as_mut(&mut self) -> &mut UserData {
|
||||||
self.has_changed = true;
|
self.mut_data()
|
||||||
&mut self.inner.data
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue