# HG changeset patch # User Yuya Nishihara # Date 1571711923 -32400 # Node ID 1f9e6fbdd3e6fc5be609fb40b585b27a882b0f3e # Parent be52b7372ec263d59cfe8af8a496f04f3d407b87 rust-cpython: remove useless wrappers from PyLeaked, just move by map() This series prepares for migrating to the upstreamed version of PySharedRef. I found this last batch wasn't queued while rewriting the callers. While Option was historically needed, it shouldn't be required anymore. I wasn't aware that each filed can be just moved. diff -r be52b7372ec2 -r 1f9e6fbdd3e6 rust/hg-cpython/src/ref_sharing.rs --- a/rust/hg-cpython/src/ref_sharing.rs Mon Jan 27 20:28:47 2020 +0100 +++ b/rust/hg-cpython/src/ref_sharing.rs Tue Oct 22 11:38:43 2019 +0900 @@ -283,7 +283,7 @@ /// borrowed. pub struct PyLeaked { inner: PyObject, - data: Option, + data: T, py_shared_state: &'static PySharedState, /// Generation counter of data `T` captured when PyLeaked is created. generation: usize, @@ -305,7 +305,7 @@ ) -> Self { Self { inner: inner.clone_ref(py), - data: Some(data), + data: data, py_shared_state, generation: py_shared_state.current_generation(py), } @@ -321,7 +321,7 @@ self.validate_generation(py)?; Ok(PyLeakedRef { _borrow: BorrowPyShared::new(py, self.py_shared_state), - data: self.data.as_ref().unwrap(), + data: &self.data, }) } @@ -338,7 +338,7 @@ self.validate_generation(py)?; Ok(PyLeakedRefMut { _borrow: BorrowPyShared::new(py, self.py_shared_state), - data: self.data.as_mut().unwrap(), + data: &mut self.data, }) } @@ -361,7 +361,7 @@ /// corresponding `PyLeaked` is alive. Do not copy it out of the /// function call. pub unsafe fn map( - mut self, + self, py: Python, f: impl FnOnce(T) -> U, ) -> PyLeaked { @@ -374,10 +374,10 @@ // 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()); + let new_data = f(self.data); PyLeaked { - inner: self.inner.clone_ref(py), - data: Some(new_data), + inner: self.inner, + data: new_data, py_shared_state: self.py_shared_state, generation: self.generation, }