Skip to content

Commit

Permalink
Move From<&T> for Py<T> impl to pyobject_native_type_core
Browse files Browse the repository at this point in the history
  • Loading branch information
kngwyu committed Oct 12, 2020
1 parent cb90c51 commit f45242f
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,6 @@ macro_rules! pyobject_native_type_named (
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()) }
}
}
};
);

Expand All @@ -97,6 +88,18 @@ macro_rules! pyobject_native_type_core {
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()) }
}
}
}
}

Expand Down

0 comments on commit f45242f

Please sign in to comment.