Move From<&T> for Py<T> impl to pyobject_native_type_core

This commit is contained in:
kngwyu 2020-10-12 13:59:52 +09:00
parent cb90c5171d
commit f45242f053
1 changed files with 12 additions and 9 deletions

View File

@ -72,15 +72,6 @@ macro_rules! pyobject_native_type_named (
unsafe { $crate::Py::from_borrowed_ptr(py, self.as_ptr()) } unsafe { $crate::Py::from_borrowed_ptr(py, self.as_ptr()) }
} }
} }
impl<$($type_param,)*> From<&'_ $name> for $crate::Py<$name> {
#[inline]
fn from(other: &$name) -> Self {
use $crate::AsPyPointer;
use $crate::PyNativeType;
unsafe { $crate::Py::from_borrowed_ptr(other.py(), other.as_ptr()) }
}
}
}; };
); );
@ -97,6 +88,18 @@ macro_rules! pyobject_native_type_core {
unsafe{&*(ob as *const $name as *const $crate::PyAny)} unsafe{&*(ob as *const $name as *const $crate::PyAny)}
} }
} }
// TODO: Rust>=1.40 allows this impl for rust-numpy.
// So we should move this to `named` or `convert` when we bump MSRV.
impl<$($type_param,)*> From<&'_ $name> for $crate::Py<$name> {
#[inline]
fn from(other: &$name) -> Self {
use $crate::AsPyPointer;
use $crate::PyNativeType;
unsafe { $crate::Py::from_borrowed_ptr(other.py(), other.as_ptr()) }
}
}
} }
} }