diff -r d782cce137fd -r b9f791090211 rust/hg-cpython/src/ref_sharing.rs --- a/rust/hg-cpython/src/ref_sharing.rs Fri Oct 18 11:18:41 2019 -0400 +++ b/rust/hg-cpython/src/ref_sharing.rs Sat Oct 12 19:10:51 2019 +0900 @@ -186,12 +186,12 @@ } /// Returns a leaked reference. - pub fn leak_immutable(&self) -> PyResult> { + pub fn leak_immutable(&self) -> PyResult> { let state = &self.data.py_shared_state; unsafe { let (static_ref, static_state_ref) = state.leak_immutable(self.py, self.data)?; - Ok(PyLeakedRef::new( + Ok(PyLeaked::new( self.py, self.owner, static_ref, @@ -307,16 +307,16 @@ } /// Manage immutable references to `PyObject` leaked into Python iterators. -pub struct PyLeakedRef { +pub struct PyLeaked { inner: PyObject, data: Option, py_shared_state: &'static PySharedState, } -// DO NOT implement Deref for PyLeakedRef! Dereferencing PyLeakedRef +// DO NOT implement Deref for PyLeaked! Dereferencing PyLeaked // without taking Python GIL wouldn't be safe. -impl PyLeakedRef { +impl PyLeaked { /// # Safety /// /// The `py_shared_state` must be owned by the `inner` Python object. @@ -355,19 +355,19 @@ /// /// The lifetime of the object passed in to the function `f` is cheated. /// It's typically a static reference, but is valid only while the - /// corresponding `PyLeakedRef` is alive. Do not copy it out of the + /// corresponding `PyLeaked` is alive. Do not copy it out of the /// function call. pub unsafe fn map( mut self, py: Python, f: impl FnOnce(T) -> U, - ) -> PyLeakedRef { + ) -> PyLeaked { // f() could make the self.data outlive. That's why map() is unsafe. // In order to make this function safe, maybe we'll need a way to // temporarily restrict the lifetime of self.data and translate the // returned object back to Something<'static>. let new_data = f(self.data.take().unwrap()); - PyLeakedRef { + PyLeaked { inner: self.inner.clone_ref(py), data: Some(new_data), py_shared_state: self.py_shared_state, @@ -375,7 +375,7 @@ } } -impl Drop for PyLeakedRef { +impl Drop for PyLeaked { fn drop(&mut self) { // py_shared_state should be alive since we do have // a Python reference to the owner object. Taking GIL makes @@ -383,7 +383,7 @@ let gil = Python::acquire_gil(); let py = gil.python(); if self.data.is_none() { - return; // moved to another PyLeakedRef + return; // moved to another PyLeaked } self.py_shared_state.decrease_leak_count(py, false); } @@ -439,7 +439,7 @@ /// /// py_shared_iterator!( /// MyTypeItemsIterator, -/// PyLeakedRef, Vec>>, +/// PyLeaked, Vec>>, /// MyType::translate_key_value, /// Option<(PyBytes, PyBytes)> /// );