use std::convert::Infallible; use pyo3::{types::PyNone, Borrowed, FromPyObject, IntoPyObject, PyAny, PyErr, Python}; #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] pub struct IsNone; impl<'a, 'py> FromPyObject<'a, 'py> for IsNone { type Error = PyErr; fn extract(ob: Borrowed<'a, 'py, PyAny>) -> Result { ob.cast::()?; Ok(IsNone) } } impl<'py> IntoPyObject<'py> for IsNone { type Target = PyNone; type Output = Borrowed<'py, 'py, Self::Target>; type Error = Infallible; fn into_pyobject(self, py: Python<'py>) -> Result { Ok(PyNone::get(py)) } }