| 1 | use std::cell::Cell; |
| 2 | |
| 3 | use crate::{ |
| 4 | conversion::IntoPyObject, types::any::PyAnyMethods, Bound, FromPyObject, PyAny, PyObject, |
| 5 | PyResult, Python, |
| 6 | }; |
| 7 | |
| 8 | #[allow (deprecated)] |
| 9 | impl<T: Copy + crate::ToPyObject> crate::ToPyObject for Cell<T> { |
| 10 | fn to_object(&self, py: Python<'_>) -> PyObject { |
| 11 | self.get().to_object(py) |
| 12 | } |
| 13 | } |
| 14 | |
| 15 | #[allow (deprecated)] |
| 16 | impl<T: Copy + crate::IntoPy<PyObject>> crate::IntoPy<PyObject> for Cell<T> { |
| 17 | fn into_py(self, py: Python<'_>) -> PyObject { |
| 18 | self.get().into_py(py) |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | impl<'py, T: Copy + IntoPyObject<'py>> IntoPyObject<'py> for Cell<T> { |
| 23 | type Target = T::Target; |
| 24 | type Output = T::Output; |
| 25 | type Error = T::Error; |
| 26 | |
| 27 | #[inline ] |
| 28 | fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> { |
| 29 | self.get().into_pyobject(py) |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | impl<'py, T: Copy + IntoPyObject<'py>> IntoPyObject<'py> for &Cell<T> { |
| 34 | type Target = T::Target; |
| 35 | type Output = T::Output; |
| 36 | type Error = T::Error; |
| 37 | |
| 38 | #[inline ] |
| 39 | fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> { |
| 40 | self.get().into_pyobject(py) |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | impl<'py, T: FromPyObject<'py>> FromPyObject<'py> for Cell<T> { |
| 45 | fn extract_bound(ob: &Bound<'py, PyAny>) -> PyResult<Self> { |
| 46 | ob.extract().map(op:Cell::new) |
| 47 | } |
| 48 | } |
| 49 | |