rust-cpython: remove useless PyRefMut wrapper
authorYuya Nishihara <yuya@tcha.org>
Sat, 05 Oct 2019 09:01:25 -0400
changeset 43429 75b4eb98ad97
parent 43428 6c0e47874217
child 43430 8418b77132c1
rust-cpython: remove useless PyRefMut wrapper
rust/hg-cpython/src/ref_sharing.rs
--- a/rust/hg-cpython/src/ref_sharing.rs	Sat Oct 05 08:59:09 2019 -0400
+++ b/rust/hg-cpython/src/ref_sharing.rs	Sat Oct 05 09:01:25 2019 -0400
@@ -61,14 +61,14 @@
         &'a self,
         py: Python<'a>,
         pyrefmut: RefMut<'a, T>,
-    ) -> PyResult<PyRefMut<'a, T>> {
+    ) -> PyResult<RefMut<'a, T>> {
         match self.current_borrow_count(py) {
             0 => {
                 // Note that this wraps around to the same value if mutably
                 // borrowed more than usize::MAX times, which wouldn't happen
                 // in practice.
                 self.generation.fetch_add(1, Ordering::Relaxed);
-                Ok(PyRefMut::new(py, pyrefmut, self))
+                Ok(pyrefmut)
             }
             _ => Err(AlreadyBorrowed::new(
                 py,
@@ -170,7 +170,7 @@
     // inner.try_borrow_mut(). The current implementation panics if
     // self.inner has been borrowed, but returns error if py_shared_state
     // refuses to borrow.
-    fn borrow_mut<'a>(&'a self, py: Python<'a>) -> PyResult<PyRefMut<'a, T>> {
+    fn borrow_mut<'a>(&'a self, py: Python<'a>) -> PyResult<RefMut<'a, T>> {
         self.py_shared_state.borrow_mut(py, self.inner.borrow_mut())
     }
 }
@@ -199,7 +199,7 @@
         self.data.borrow(self.py)
     }
 
-    pub fn borrow_mut(&self) -> PyResult<PyRefMut<'a, T>> {
+    pub fn borrow_mut(&self) -> PyResult<RefMut<'a, T>> {
         self.data.borrow_mut(self.py)
     }
 
@@ -226,38 +226,6 @@
     }
 }
 
-/// Holds a mutable reference to data shared between Python and Rust.
-pub struct PyRefMut<'a, T> {
-    inner: RefMut<'a, T>,
-}
-
-impl<'a, T> PyRefMut<'a, T> {
-    // Must be constructed by PySharedState after checking its leak_count.
-    // Otherwise, drop() would incorrectly update the state.
-    fn new(
-        _py: Python<'a>,
-        inner: RefMut<'a, T>,
-        _py_shared_state: &'a PySharedState,
-    ) -> Self {
-        Self {
-            inner,
-        }
-    }
-}
-
-impl<'a, T> std::ops::Deref for PyRefMut<'a, T> {
-    type Target = RefMut<'a, T>;
-
-    fn deref(&self) -> &Self::Target {
-        &self.inner
-    }
-}
-impl<'a, T> std::ops::DerefMut for PyRefMut<'a, T> {
-    fn deref_mut(&mut self) -> &mut Self::Target {
-        &mut self.inner
-    }
-}
-
 /// Allows a `py_class!` generated struct to share references to one of its
 /// data members with Python.
 ///