chore+feat(python-utils): update to pyo3 0.27, introduce helpers like FromPyObjectViaParse and IntoPyObjectViaDisplay before I make macros that can complement or replace them

This commit is contained in:
2026-01-07 02:14:58 -05:00
parent eff0ad2bf8
commit 48f29ea7d6
3 changed files with 166 additions and 32 deletions

27
python-utils/src/none.rs Normal file
View File

@@ -0,0 +1,27 @@
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<Self, Self::Error> {
ob.cast::<PyNone>()?;
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<Self::Output, Self::Error> {
Ok(PyNone::get(py))
}
}