Fix impl FromPyObject for Py<T>

This commit is contained in:
Nikolay Kim 2018-01-17 08:09:44 -08:00
parent 9a141fb921
commit d6035bce15
2 changed files with 7 additions and 2 deletions

View File

@ -1,6 +1,10 @@
Changes
-------
0.2.4 (2018-01-xx)
* Fix impl `FromPyObject` for `Py<T>`
* Mark method that work with raw pointers as unsafe #95

View File

@ -328,13 +328,14 @@ impl<'a, T> std::convert::From<&'a mut T> for PyObject
}
}
impl<'a, T> FromPyObject<'a> for Py<T> where T: ToPyPointer + FromPyObject<'a>
impl<'a, T> FromPyObject<'a> for Py<T>
where T: ToPyPointer, &'a T: 'a + FromPyObject<'a>
{
/// Extracts `Self` from the source `PyObject`.
fn extract(ob: &'a PyObjectRef) -> PyResult<Self>
{
unsafe {
ob.extract::<T>().map(|val| Py::from_borrowed_ptr(val.as_ptr()))
ob.extract::<&T>().map(|val| Py::from_borrowed_ptr(val.as_ptr()))
}
}
}