Skip to content

Commit

Permalink
Implement DerefMut on RoTxn for heed3
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerollmops committed Mar 6, 2025
1 parent ed9b259 commit b883def
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions heed/src/txn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ impl<'a> Deref for RoTxn<'a, WithTls> {
}
}

#[cfg(master3)]
impl<'a> std::ops::DerefMut for RoTxn<'a, WithTls> {
fn deref_mut(&mut self) -> &mut Self::Target {
// SAFETY: OK because repr(transparent) means RoTxn<T> always has the same layout
// as RoTxnInner.
unsafe { std::mem::transmute(self) }
}
}

impl<'a> Deref for RoTxn<'a, WithoutTls> {
type Target = RoTxn<'a, AnyTls>;

Expand All @@ -151,6 +160,15 @@ impl<'a> Deref for RoTxn<'a, WithoutTls> {
}
}

#[cfg(master3)]
impl<'a> std::ops::DerefMut for RoTxn<'a, WithoutTls> {
fn deref_mut(&mut self) -> &mut Self::Target {
// SAFETY: OK because repr(transparent) means RoTxn<T> always has the same layout
// as RoTxnInner.
unsafe { std::mem::transmute(self) }
}
}

impl<T> Drop for RoTxn<'_, T> {
fn drop(&mut self) {
if let Some(mut txn) = self.inner.txn.take() {
Expand Down

0 comments on commit b883def

Please sign in to comment.