Remove usage of `AsPyPointer` in `IntoPy<PyObject>` trait implementation
This commit is contained in:
parent
9363491d54
commit
9f1b56b659
|
@ -0,0 +1 @@
|
|||
Replace blanket `impl IntoPy<PyObject> for &T where T: AsPyPointer` with implementations of `impl IntoPy<PyObject>` for `&PyAny`, `&T where T: AsRef<PyAny>`, and `&Py<T>`.
|
|
@ -276,16 +276,23 @@ impl IntoPy<PyObject> for () {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> IntoPy<PyObject> for &'_ T
|
||||
where
|
||||
T: AsPyPointer,
|
||||
{
|
||||
impl IntoPy<PyObject> for &'_ PyAny {
|
||||
#[inline]
|
||||
fn into_py(self, py: Python<'_>) -> PyObject {
|
||||
unsafe { PyObject::from_borrowed_ptr(py, self.as_ptr()) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> IntoPy<PyObject> for &'_ T
|
||||
where
|
||||
T: AsRef<PyAny>,
|
||||
{
|
||||
#[inline]
|
||||
fn into_py(self, py: Python<'_>) -> PyObject {
|
||||
unsafe { PyObject::from_borrowed_ptr(py, self.as_ref().as_ptr()) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Copy + ToPyObject> ToPyObject for Cell<T> {
|
||||
fn to_object(&self, py: Python<'_>) -> PyObject {
|
||||
self.get().to_object(py)
|
||||
|
|
|
@ -925,6 +925,13 @@ impl<T> IntoPy<PyObject> for Py<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> IntoPy<PyObject> for &'_ Py<T> {
|
||||
#[inline]
|
||||
fn into_py(self, py: Python<'_>) -> PyObject {
|
||||
self.to_object(py)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> crate::AsPyPointer for Py<T> {
|
||||
/// Gets the underlying FFI pointer, returns a borrowed pointer.
|
||||
#[inline]
|
||||
|
|
|
@ -743,6 +743,12 @@ impl<T: PyClass> IntoPy<PyObject> for PyRef<'_, T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: PyClass> IntoPy<PyObject> for &'_ PyRef<'_, T> {
|
||||
fn into_py(self, py: Python<'_>) -> PyObject {
|
||||
self.inner.into_py(py)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: PyClass> std::convert::TryFrom<&'a PyCell<T>> for crate::PyRef<'a, T> {
|
||||
type Error = PyBorrowError;
|
||||
fn try_from(cell: &'a crate::PyCell<T>) -> Result<Self, Self::Error> {
|
||||
|
@ -867,6 +873,12 @@ impl<T: PyClass<Frozen = False>> IntoPy<PyObject> for PyRefMut<'_, T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: PyClass<Frozen = False>> IntoPy<PyObject> for &'_ PyRefMut<'_, T> {
|
||||
fn into_py(self, py: Python<'_>) -> PyObject {
|
||||
self.inner.into_py(py)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: PyClass<Frozen = False>> AsPyPointer for PyRefMut<'a, T> {
|
||||
fn as_ptr(&self) -> *mut ffi::PyObject {
|
||||
self.inner.as_ptr()
|
||||
|
|
Loading…
Reference in New Issue