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:
27
python-utils/src/none.rs
Normal file
27
python-utils/src/none.rs
Normal 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))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user