migrate `FromPyObject` for `Bound` and `Py` to `extract_bound`
This commit is contained in:
parent
7549a21154
commit
a3eb328378
|
@ -0,0 +1 @@
|
|||
Relax bound of `FromPyObject` for `Py<T>` to just `T: PyTypeCheck`.
|
|
@ -1405,27 +1405,22 @@ impl<T> Drop for Py<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, T> FromPyObject<'a> for Py<T>
|
||||
impl<T> FromPyObject<'_> for Py<T>
|
||||
where
|
||||
T: PyTypeInfo,
|
||||
&'a T::AsRefTarget: FromPyObject<'a>,
|
||||
T::AsRefTarget: 'a + AsPyPointer,
|
||||
T: PyTypeCheck,
|
||||
{
|
||||
/// Extracts `Self` from the source `PyObject`.
|
||||
fn extract(ob: &'a PyAny) -> PyResult<Self> {
|
||||
unsafe {
|
||||
ob.extract::<&T::AsRefTarget>()
|
||||
.map(|val| Py::from_borrowed_ptr(ob.py(), val.as_ptr()))
|
||||
}
|
||||
fn extract_bound(ob: &Bound<'_, PyAny>) -> PyResult<Self> {
|
||||
ob.extract::<Bound<'_, T>>().map(Bound::unbind)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T> FromPyObject<'a> for Bound<'a, T>
|
||||
impl<'py, T> FromPyObject<'py> for Bound<'py, T>
|
||||
where
|
||||
T: PyTypeInfo,
|
||||
T: PyTypeCheck,
|
||||
{
|
||||
/// Extracts `Self` from the source `PyObject`.
|
||||
fn extract_bound(ob: &Bound<'a, PyAny>) -> PyResult<Self> {
|
||||
fn extract_bound(ob: &Bound<'py, PyAny>) -> PyResult<Self> {
|
||||
ob.downcast().map(Clone::clone).map_err(Into::into)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue