Separate FromPyObjectImpl from pyobject_native_type_convert!
This commit is contained in:
parent
99a7856dad
commit
d1f28e9089
|
@ -33,6 +33,7 @@ pyobject_native_type_convert!(
|
|||
Some("builtins"),
|
||||
ffi::PyObject_Check
|
||||
);
|
||||
pyobject_native_type_extract!(PyAny);
|
||||
|
||||
impl PyAny {
|
||||
pub fn downcast_ref<T>(&self) -> Result<&T, PyDowncastError>
|
||||
|
|
|
@ -63,6 +63,7 @@ macro_rules! pyobject_native_type {
|
|||
impl $crate::type_object::PyObjectSizedLayout<$name> for $layout {}
|
||||
pyobject_native_type_named!($name $(,$type_param)*);
|
||||
pyobject_native_type_convert!($name, $layout, $typeobject, $module, $checkfunction $(,$type_param)*);
|
||||
pyobject_native_type_extract!($name $(,$type_param)*);
|
||||
|
||||
impl<'a, $($type_param,)*> ::std::convert::From<&'a $name> for &'a $crate::types::PyAny {
|
||||
fn from(ob: &'a $name) -> Self {
|
||||
|
@ -84,6 +85,8 @@ macro_rules! pyobject_native_var_type {
|
|||
pyobject_native_type_named!($name $(,$type_param)*);
|
||||
pyobject_native_type_convert!($name, $crate::ffi::PyObject,
|
||||
$typeobject, $module, $checkfunction $(,$type_param)*);
|
||||
pyobject_native_type_extract!($name $(,$type_param)*);
|
||||
|
||||
impl<'a, $($type_param,)*> ::std::convert::From<&'a $name> for &'a $crate::types::PyAny {
|
||||
fn from(ob: &'a $name) -> Self {
|
||||
unsafe{&*(ob as *const $name as *const $crate::types::PyAny)}
|
||||
|
@ -97,6 +100,16 @@ macro_rules! pyobject_native_var_type {
|
|||
};
|
||||
}
|
||||
|
||||
// NOTE: This macro is not included in pyobject_native_type_convert!
|
||||
// because rust-numpy has a special implementation.
|
||||
macro_rules! pyobject_native_type_extract {
|
||||
($name: ty $(,$type_param: ident)*) => {
|
||||
impl<$($type_param,)*> $crate::conversion::FromPyObjectImpl for &'_ $name {
|
||||
type Impl = $crate::conversion::extract_impl::Reference;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! pyobject_native_type_convert(
|
||||
($name: ty, $layout: path, $typeobject: expr,
|
||||
|
@ -142,10 +155,6 @@ macro_rules! pyobject_native_type_convert(
|
|||
}
|
||||
}
|
||||
|
||||
impl<$($type_param,)*> $crate::conversion::FromPyObjectImpl for &'_ $name {
|
||||
type Impl = $crate::conversion::extract_impl::Reference;
|
||||
}
|
||||
|
||||
impl<$($type_param,)*> ::std::fmt::Debug for $name {
|
||||
fn fmt(&self, f: &mut ::std::fmt::Formatter)
|
||||
-> Result<(), ::std::fmt::Error>
|
||||
|
|
Loading…
Reference in a new issue