Skip to content

Commit

Permalink
Implement DerefMut
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Jul 29, 2024
1 parent 4995ce0 commit 12e0741
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,15 @@ impl<U: UserData> std::ops::Deref for DatabaseImpl<U> {
}
}

impl<U: UserData> std::ops::DerefMut for DatabaseImpl<U> {
fn deref_mut(&mut self) -> &mut U {
self.zalsa_mut()
.user_data_mut()
.downcast_mut::<U>()
.unwrap()
}
}

impl<U: UserData + RefUnwindSafe> RefUnwindSafe for DatabaseImpl<U> {}

#[salsa_macros::db]
Expand Down
4 changes: 4 additions & 0 deletions src/zalsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ impl Zalsa {
&*self.user_data
}

pub(crate) fn user_data_mut(&mut self) -> &mut (dyn Any + Send + Sync) {
&mut *self.user_data
}

/// Triggers a new revision. Invoked automatically when you call `zalsa_mut`
/// and so doesn't need to be called otherwise.
pub(crate) fn new_revision(&mut self) -> Revision {
Expand Down

0 comments on commit 12e0741

Please sign in to comment.