pyo3/conversions/std/
cell.rs1use std::cell::Cell;
2
3use crate::{
4 conversion::IntoPyObject, types::any::PyAnyMethods, Bound, FromPyObject, PyAny, PyResult,
5 Python,
6};
7
8impl<'py, T: Copy + IntoPyObject<'py>> IntoPyObject<'py> for Cell<T> {
9 type Target = T::Target;
10 type Output = T::Output;
11 type Error = T::Error;
12
13 #[cfg(feature = "experimental-inspect")]
14 const OUTPUT_TYPE: &'static str = T::OUTPUT_TYPE;
15
16 #[inline]
17 fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> {
18 self.get().into_pyobject(py)
19 }
20}
21
22impl<'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 #[cfg(feature = "experimental-inspect")]
28 const OUTPUT_TYPE: &'static str = T::OUTPUT_TYPE;
29
30 #[inline]
31 fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> {
32 self.get().into_pyobject(py)
33 }
34}
35
36impl<'py, T: FromPyObject<'py>> FromPyObject<'py> for Cell<T> {
37 #[cfg(feature = "experimental-inspect")]
38 const INPUT_TYPE: &'static str = T::INPUT_TYPE;
39
40 fn extract_bound(ob: &Bound<'py, PyAny>) -> PyResult<Self> {
41 ob.extract().map(Cell::new)
42 }
43}