Skip to content

Commit 12e0741

Browse files
committed
Implement DerefMut
1 parent 4995ce0 commit 12e0741

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/database.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,15 @@ impl<U: UserData> std::ops::Deref for DatabaseImpl<U> {
196196
}
197197
}
198198

199+
impl<U: UserData> std::ops::DerefMut for DatabaseImpl<U> {
200+
fn deref_mut(&mut self) -> &mut U {
201+
self.zalsa_mut()
202+
.user_data_mut()
203+
.downcast_mut::<U>()
204+
.unwrap()
205+
}
206+
}
207+
199208
impl<U: UserData + RefUnwindSafe> RefUnwindSafe for DatabaseImpl<U> {}
200209

201210
#[salsa_macros::db]

src/zalsa.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ impl Zalsa {
179179
&*self.user_data
180180
}
181181

182+
pub(crate) fn user_data_mut(&mut self) -> &mut (dyn Any + Send + Sync) {
183+
&mut *self.user_data
184+
}
185+
182186
/// Triggers a new revision. Invoked automatically when you call `zalsa_mut`
183187
/// and so doesn't need to be called otherwise.
184188
pub(crate) fn new_revision(&mut self) -> Revision {

0 commit comments

Comments
 (0)